aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2022-11-08 10:46:07 +0200
committeraqua <aqua@iserlohn-fortress.net>2022-11-08 14:56:42 +0200
commit527a5ea7a896a9b00e0563abbbed7771a398971b (patch)
tree81dcbe1b95c88bea447dfcc32d6fed46835713bb /lib
parentCapture ps2 mouse packets (diff)
downloadkernel-527a5ea7a896a9b00e0563abbbed7771a398971b.tar.xz
Add python-sphinx docs
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile5
-rw-r--r--lib/memset.c14
-rw-r--r--lib/stdlib.h19
-rw-r--r--lib/stdlib/memcpy.c (renamed from lib/memcpy.c)7
-rw-r--r--lib/stdlib/memset.c7
-rw-r--r--lib/string.h10
-rw-r--r--lib/tst/mem.cc4
7 files changed, 39 insertions, 27 deletions
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/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 <stddef.h>
+/**
+ * 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/memcpy.c b/lib/stdlib/memcpy.c
index 059738f..90470d5 100644
--- a/lib/memcpy.c
+++ b/lib/stdlib/memcpy.c
@@ -1,10 +1,3 @@
-/**
- * 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)
{
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)