Add the sys directory for libc functions which use system calls; move the
authorDavid Given <dg@cowlark.com>
Sat, 23 Jun 2018 16:08:03 +0000 (18:08 +0200)
committerDavid Given <dg@cowlark.com>
Sat, 23 Jun 2018 16:08:03 +0000 (18:08 +0200)
malloc functions in there.

lang/cem/libcc.ansi/build.lua
lang/cem/libcc.ansi/sys/README.md [new file with mode: 0644]
lang/cem/libcc.ansi/sys/malloc/calloc.c [moved from lang/cem/libcc.ansi/malloc/calloc.c with 93% similarity]
lang/cem/libcc.ansi/sys/malloc/malloc.c [moved from lang/cem/libcc.ansi/malloc/malloc.c with 98% similarity]
lang/cem/libcc.ansi/sys/malloc/malloc.h [moved from lang/cem/libcc.ansi/malloc/malloc.h with 100% similarity]
lang/cem/libcc.ansi/sys/malloc/realloc.c [moved from lang/cem/libcc.ansi/malloc/realloc.c with 95% similarity]

index 18b2a44..38fba6b 100644 (file)
@@ -43,8 +43,7 @@ for _, plat in ipairs(vars.plats) do
                        "./core/math/*.e",
                        "./core/ctype/*.c",
                        "./core/misc/*.c",
-                       "./errno/*.c",
-                       "./malloc/*.c",
+                       "./sys/malloc/*.c",
                        "./signal/*.c",
                        "./assert/*.c",
                        "./stdio/*.c",
@@ -58,7 +57,7 @@ for _, plat in ipairs(vars.plats) do
                deps = {
                        "lang/cem/libcc.ansi/headers+pkg",
                        "plat/"..plat.."/include+pkg",
-                       "./malloc/malloc.h",
+                       "./sys/malloc/malloc.h",
                        "./core/math/localmath.h",
                        "./core/stdlib/ext_fmt.h",
                        "./stdio/loc_incl.h",
diff --git a/lang/cem/libcc.ansi/sys/README.md b/lang/cem/libcc.ansi/sys/README.md
new file mode 100644 (file)
index 0000000..b38a2f0
--- /dev/null
@@ -0,0 +1,4 @@
+The functions here all use Posix system calls to do the actual work, and so
+require `unistd.h` (at the minimum). Typically each group of functions will
+be protected by an `ACKCONF` variable so the plat can turn them on and off as
+necessary.
similarity index 93%
rename from lang/cem/libcc.ansi/malloc/calloc.c
rename to lang/cem/libcc.ansi/sys/malloc/calloc.c
index 8695f17..e21c526 100644 (file)
@@ -3,6 +3,8 @@
 #include <unistd.h>
 #include <string.h>
 
+#if ACKCONF_WANT_MALLOC
+
 void* calloc(size_t nmemb, size_t size)
 {
        size_t bytes = nmemb * size;
@@ -22,3 +24,5 @@ void* calloc(size_t nmemb, size_t size)
        memset(ptr, 0, bytes);
        return ptr;
 }
+
+#endif
similarity index 98%
rename from lang/cem/libcc.ansi/malloc/malloc.c
rename to lang/cem/libcc.ansi/sys/malloc/malloc.c
index 71f3c80..ea13816 100644 (file)
@@ -3,6 +3,8 @@
 #include <unistd.h>
 #include "malloc.h"
 
+#if ACKCONF_WANT_MALLOC
+
 block_t __mem_root = { &__mem_root, 0 };
 block_t* __mem_freelist = &__mem_root;
 
@@ -148,3 +150,5 @@ void free(void* ptr)
        /* ...and update the ring pointer. */
        __mem_freelist = p;
 }
+
+#endif
similarity index 95%
rename from lang/cem/libcc.ansi/malloc/realloc.c
rename to lang/cem/libcc.ansi/sys/malloc/realloc.c
index c941d80..6e2b4c9 100644 (file)
@@ -4,6 +4,8 @@
 #include <string.h>
 #include "malloc.h"
 
+#if ACKCONF_WANT_MALLOC
+
 void* realloc(void* ptr, size_t size)
 {
        block_t* h;
@@ -39,3 +41,5 @@ void* realloc(void* ptr, size_t size)
        free(ptr);
        return newptr;
 }
+
+#endif