diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index 18b2a44d6..38fba6bb3 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -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 index 000000000..b38a2f08f --- /dev/null +++ b/lang/cem/libcc.ansi/sys/README.md @@ -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. diff --git a/lang/cem/libcc.ansi/malloc/calloc.c b/lang/cem/libcc.ansi/sys/malloc/calloc.c similarity index 93% rename from lang/cem/libcc.ansi/malloc/calloc.c rename to lang/cem/libcc.ansi/sys/malloc/calloc.c index 8695f17f0..e21c5266a 100644 --- a/lang/cem/libcc.ansi/malloc/calloc.c +++ b/lang/cem/libcc.ansi/sys/malloc/calloc.c @@ -3,6 +3,8 @@ #include #include +#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 diff --git a/lang/cem/libcc.ansi/malloc/malloc.c b/lang/cem/libcc.ansi/sys/malloc/malloc.c similarity index 98% rename from lang/cem/libcc.ansi/malloc/malloc.c rename to lang/cem/libcc.ansi/sys/malloc/malloc.c index 71f3c80b2..ea1381600 100644 --- a/lang/cem/libcc.ansi/malloc/malloc.c +++ b/lang/cem/libcc.ansi/sys/malloc/malloc.c @@ -3,6 +3,8 @@ #include #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 diff --git a/lang/cem/libcc.ansi/malloc/malloc.h b/lang/cem/libcc.ansi/sys/malloc/malloc.h similarity index 100% rename from lang/cem/libcc.ansi/malloc/malloc.h rename to lang/cem/libcc.ansi/sys/malloc/malloc.h diff --git a/lang/cem/libcc.ansi/malloc/realloc.c b/lang/cem/libcc.ansi/sys/malloc/realloc.c similarity index 95% rename from lang/cem/libcc.ansi/malloc/realloc.c rename to lang/cem/libcc.ansi/sys/malloc/realloc.c index c941d8091..6e2b4c924 100644 --- a/lang/cem/libcc.ansi/malloc/realloc.c +++ b/lang/cem/libcc.ansi/sys/malloc/realloc.c @@ -4,6 +4,8 @@ #include #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