From ea8882dd7c024db436e25e86ac3d3fa3b3e43aa0 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sun, 21 Dec 2025 17:14:52 -0500 Subject: usr: sdk: Add initial string lib sources + strlen Signed-off-by: Ian Moffett --- mk/defaults.mk | 1 + usr/.keep | 0 usr/sdk/Makefile | 21 +++++++++++++++++++++ usr/sdk/common/string/strlen.c | 20 ++++++++++++++++++++ usr/sdk/inc/sdk/string.h | 18 ++++++++++++++++++ 5 files changed, 60 insertions(+) delete mode 100644 usr/.keep create mode 100644 usr/sdk/Makefile create mode 100644 usr/sdk/common/string/strlen.c create mode 100644 usr/sdk/inc/sdk/string.h diff --git a/mk/defaults.mk b/mk/defaults.mk index ae85cfd..2c06603 100644 --- a/mk/defaults.mk +++ b/mk/defaults.mk @@ -8,6 +8,7 @@ QEMU = qemu-system-$(ARCH) CC = $(shell pwd)/var/cc/gcc/bin/$(ARCH)-pc-osmora-gcc LD = $(shell pwd)/var/cc/toolchain/build-binutils/bin/$(ARCH)-pc-osmora-ld +AR = $(shell pwd)/var/cc/toolchain/build-binutils/bin/$(ARCH)-pc-osmora-ar SYS_CFLAGS = \ -nostdlib \ diff --git a/usr/.keep b/usr/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/usr/sdk/Makefile b/usr/sdk/Makefile new file mode 100644 index 0000000..9a5cc73 --- /dev/null +++ b/usr/sdk/Makefile @@ -0,0 +1,21 @@ +# +# Copyright (c) 2025, Ian Moffett. +# Provided under the BSD-3 clause. +# + +CFILES = $(shell find common/ -name "*.c") +OFILES = $(CFILES:.c=.o) + +CC = +LD = + +ARCH = +SYS_CFLAGS = +CFLAGS = $(SYS_CFLAGS) -Iinc/ + +.PHONY: all +all: $(OFILES) + $(AR) rcs libmos.a $(OFILES) + +%.o: %.c + $(CC) -c $(CFLAGS) $< -o $@ diff --git a/usr/sdk/common/string/strlen.c b/usr/sdk/common/string/strlen.c new file mode 100644 index 0000000..4499512 --- /dev/null +++ b/usr/sdk/common/string/strlen.c @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025, Ian Moffett. + * Provided under the BSD-3 clause. + */ + +#include +#include + +USIZE +strlen(const char *str) +{ + USIZE len = 0; + + if (str == NULL) { + return 0; + } + + while (str[len++] != '\0'); + return len - 1; +} diff --git a/usr/sdk/inc/sdk/string.h b/usr/sdk/inc/sdk/string.h new file mode 100644 index 0000000..f7668fd --- /dev/null +++ b/usr/sdk/inc/sdk/string.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025, Ian Moffett. + * Provided under the BSD-3 clause. + */ + +#ifndef _SDK_STRING_H_ +#define _SDK_STRING_H_ 1 + + #include + +/* + * Returns the length of a string + * + * @str: String to get length of + */ +USIZE strlen(const char *str); + +#endif /* !_SDK_STRING_H_ */ -- cgit v1.2.3