diff --git a/libs/libc/include/stdlib.h b/libs/libc/include/stdlib.h index e070f93a..f8380026 100644 --- a/libs/libc/include/stdlib.h +++ b/libs/libc/include/stdlib.h @@ -9,13 +9,37 @@ extern "C" { #endif + /* Aborts the program. */ noreturn void abort(); - noreturn void exit(int); + + /* Exits the program with the specified status code. */ + noreturn void exit(int status); + + /* Not implemented. */ int atexit(void (*)(void)); + + /* Not implemented.*/ int atoi(const char*); - void free(void*); + + /* Not implemented. */ char* getenv(const char*); - void* malloc(size_t); + + /* Allocates n bytes of memory and returns a pointer to it. This memory should be freed by calling free() when it is + * not in use anymore. */ + void* malloc(size_t n); + + /* Allocates enough bytes of memory for an array containing nmemb items of size n and returns a pointer to it. This + * memory should be freed by calling free() when it is not in use anymore. */ + void* calloc(size_t nmemb, size_t n); + + /* Resizes memory allocated by malloc() or calloc() to n bytes. Returns a pointer to the new resized region of + * memory, which should be used instead of the old one. This memory should be freed by calling free() when it is not + * in use anymore. */ + void* realloc(void* ptr, size_t n); + + /* Frees a pointer to memory allocated by malloc(), calloc() or realloc(). Accessing the contents of ptr afterwards + * is undefined behavior. */ + void free(void* ptr); #ifdef __cplusplus } diff --git a/libs/libc/src/stdlib.cpp b/libs/libc/src/stdlib.cpp index 427c6ec7..9841f6de 100644 --- a/libs/libc/src/stdlib.cpp +++ b/libs/libc/src/stdlib.cpp @@ -3,11 +3,6 @@ #include #include -#define noreturn __attribute__((noreturn)) - -#define maybe_unused __attribute__((maybe_unused)) -#define unused __attribute__((unused)) - extern "C" { noreturn void abort() @@ -25,10 +20,12 @@ extern "C" { NOT_IMPLEMENTED("atexit"); } + int atoi(const char*) { NOT_IMPLEMENTED("atoi"); } + char* getenv(const char*) { NOT_IMPLEMENTED("getenv");