Add the sys directory for libc functions which use system calls; move the

malloc functions in there.
This commit is contained in:
David Given 2018-06-23 18:08:03 +02:00
parent c4e4505a73
commit df1cdf7762
6 changed files with 18 additions and 3 deletions

View 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",

View file

@ -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.

View 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

View 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

View 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