Add the sys directory for libc functions which use system calls; move the
malloc functions in there.
This commit is contained in:
parent
c4e4505a73
commit
df1cdf7762
|
@ -43,8 +43,7 @@ for _, plat in ipairs(vars.plats) do
|
||||||
"./core/math/*.e",
|
"./core/math/*.e",
|
||||||
"./core/ctype/*.c",
|
"./core/ctype/*.c",
|
||||||
"./core/misc/*.c",
|
"./core/misc/*.c",
|
||||||
"./errno/*.c",
|
"./sys/malloc/*.c",
|
||||||
"./malloc/*.c",
|
|
||||||
"./signal/*.c",
|
"./signal/*.c",
|
||||||
"./assert/*.c",
|
"./assert/*.c",
|
||||||
"./stdio/*.c",
|
"./stdio/*.c",
|
||||||
|
@ -58,7 +57,7 @@ for _, plat in ipairs(vars.plats) do
|
||||||
deps = {
|
deps = {
|
||||||
"lang/cem/libcc.ansi/headers+pkg",
|
"lang/cem/libcc.ansi/headers+pkg",
|
||||||
"plat/"..plat.."/include+pkg",
|
"plat/"..plat.."/include+pkg",
|
||||||
"./malloc/malloc.h",
|
"./sys/malloc/malloc.h",
|
||||||
"./core/math/localmath.h",
|
"./core/math/localmath.h",
|
||||||
"./core/stdlib/ext_fmt.h",
|
"./core/stdlib/ext_fmt.h",
|
||||||
"./stdio/loc_incl.h",
|
"./stdio/loc_incl.h",
|
||||||
|
|
4
lang/cem/libcc.ansi/sys/README.md
Normal file
4
lang/cem/libcc.ansi/sys/README.md
Normal 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.
|
|
@ -3,6 +3,8 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#if ACKCONF_WANT_MALLOC
|
||||||
|
|
||||||
void* calloc(size_t nmemb, size_t size)
|
void* calloc(size_t nmemb, size_t size)
|
||||||
{
|
{
|
||||||
size_t bytes = nmemb * size;
|
size_t bytes = nmemb * size;
|
||||||
|
@ -22,3 +24,5 @@ void* calloc(size_t nmemb, size_t size)
|
||||||
memset(ptr, 0, bytes);
|
memset(ptr, 0, bytes);
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -3,6 +3,8 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "malloc.h"
|
#include "malloc.h"
|
||||||
|
|
||||||
|
#if ACKCONF_WANT_MALLOC
|
||||||
|
|
||||||
block_t __mem_root = { &__mem_root, 0 };
|
block_t __mem_root = { &__mem_root, 0 };
|
||||||
block_t* __mem_freelist = &__mem_root;
|
block_t* __mem_freelist = &__mem_root;
|
||||||
|
|
||||||
|
@ -148,3 +150,5 @@ void free(void* ptr)
|
||||||
/* ...and update the ring pointer. */
|
/* ...and update the ring pointer. */
|
||||||
__mem_freelist = p;
|
__mem_freelist = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -4,6 +4,8 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "malloc.h"
|
#include "malloc.h"
|
||||||
|
|
||||||
|
#if ACKCONF_WANT_MALLOC
|
||||||
|
|
||||||
void* realloc(void* ptr, size_t size)
|
void* realloc(void* ptr, size_t size)
|
||||||
{
|
{
|
||||||
block_t* h;
|
block_t* h;
|
||||||
|
@ -39,3 +41,5 @@ void* realloc(void* ptr, size_t size)
|
||||||
free(ptr);
|
free(ptr);
|
||||||
return newptr;
|
return newptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue