From 527a5ea7a896a9b00e0563abbbed7771a398971b Mon Sep 17 00:00:00 2001 From: aqua Date: Tue, 8 Nov 2022 10:46:07 +0200 Subject: Add python-sphinx docs --- lib/Makefile | 5 +++-- lib/memcpy.c | 20 -------------------- lib/memset.c | 14 -------------- lib/stdlib.h | 19 +++++++++++++++++-- lib/stdlib/memcpy.c | 13 +++++++++++++ lib/stdlib/memset.c | 7 +++++++ lib/string.h | 10 ++++++++++ lib/tst/mem.cc | 4 ++-- 8 files changed, 52 insertions(+), 40 deletions(-) delete mode 100644 lib/memcpy.c delete mode 100644 lib/memset.c create mode 100644 lib/stdlib/memcpy.c create mode 100644 lib/stdlib/memset.c (limited to 'lib') diff --git a/lib/Makefile b/lib/Makefile index dec0769..66181c8 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -2,11 +2,12 @@ include ../Makefile.config CCFLAGS += -I. -I.. -libk.SRCS = memcpy.c memset.c stdio/printf.c string/itoa.c +libk.SRCS = stdio/printf.c \ + stdlib/memcpy.c stdlib/memset.c \ + string/itoa.c include ../rules.mk .PHONY: test test: tst/test_mem tst/test_string tst/test_linked_list_allocator - @echo $^ $(foreach f,$^,./$f;) diff --git a/lib/memcpy.c b/lib/memcpy.c deleted file mode 100644 index 059738f..0000000 --- a/lib/memcpy.c +++ /dev/null @@ -1,20 +0,0 @@ -/** - * The memcpy() function copies n bytes from memory area src to memory area dest. The memory areas must not overlap. - * @param dest - * @param src - * @param n - * @return - */ -void * -memcpy(void *restrict dest, const void *restrict src, long unsigned n) -{ - char *pDest = (char *)dest; - const char *pSrc = (const char *)src; - - while (n) { - *(pDest++) = *(pSrc++); - --n; - } - - return dest; -} diff --git a/lib/memset.c b/lib/memset.c deleted file mode 100644 index 670e4b6..0000000 --- a/lib/memset.c +++ /dev/null @@ -1,14 +0,0 @@ -/** - * The memset() function fills the first n bytes of the memory area pointed to by s with the constant byte c. - * @param s - * @param c - * @param n - * @return - */ -void * -memset(void *s, int c, long unsigned n) -{ - char *pDest = (char *)s; - for (unsigned i = 0; i < n; ++i) pDest[i] = c; - return s; -} diff --git a/lib/stdlib.h b/lib/stdlib.h index 6b8e09d..7f235f0 100644 --- a/lib/stdlib.h +++ b/lib/stdlib.h @@ -1,6 +1,21 @@ #pragma once -#include +/** + * Allocate size bytes and return a pointer to the allocated memory + */ +void *malloc(unsigned int size); -void *malloc(size_t size); +/** + * Free the memory space pointed to by ptr + */ void free(void *ptr); + +/** + * Fill the first n bytes of the memory area pointed to by s with the constant byte c. + */ +void *memset(void *s, int c, long unsigned n); + +/** + * Copy n bytes from memory area src to memory area dest. The memory areas must not overlap. + */ +void *memcpy(void *restrict dest, const void *restrict src, long unsigned n); diff --git a/lib/stdlib/memcpy.c b/lib/stdlib/memcpy.c new file mode 100644 index 0000000..90470d5 --- /dev/null +++ b/lib/stdlib/memcpy.c @@ -0,0 +1,13 @@ +void * +memcpy(void *restrict dest, const void *restrict src, long unsigned n) +{ + char *pDest = (char *)dest; + const char *pSrc = (const char *)src; + + while (n) { + *(pDest++) = *(pSrc++); + --n; + } + + return dest; +} diff --git a/lib/stdlib/memset.c b/lib/stdlib/memset.c new file mode 100644 index 0000000..ccd46dd --- /dev/null +++ b/lib/stdlib/memset.c @@ -0,0 +1,7 @@ +void * +memset(void *s, int c, long unsigned n) +{ + char *pDest = (char *)s; + for (unsigned i = 0; i < n; ++i) pDest[i] = c; + return s; +} diff --git a/lib/string.h b/lib/string.h index 9873362..1eb3da2 100644 --- a/lib/string.h +++ b/lib/string.h @@ -1,4 +1,14 @@ #pragma once +#define OCTAL 8 +#define DECIMAL 10 +#define HEX 16 + +/** + * Convert int into a string + */ char *itoa(char *p, int x, int base); +/** + * Convert unsigned int into a string + */ char *utoa(char *p, unsigned x, int base); diff --git a/lib/tst/mem.cc b/lib/tst/mem.cc index b233da8..7586a97 100644 --- a/lib/tst/mem.cc +++ b/lib/tst/mem.cc @@ -3,8 +3,8 @@ #define restrict __restrict__ namespace libk { -#include "../memcpy.c" -#include "../memset.c" +#include "../stdlib/memcpy.c" +#include "../stdlib/memset.c" } // namespace libk TEST(mem, memset) -- cgit v1.2.1