libc: Document functions in stdlib.h

Also, add prototypes for calloc() and realloc(), which were already implemented but not in the header.
This commit is contained in:
apio 2022-10-12 11:30:21 +02:00
parent c8c4d31cca
commit ffc223c2cf
2 changed files with 29 additions and 8 deletions

View File

@ -9,13 +9,37 @@ extern "C"
{ {
#endif #endif
/* Aborts the program. */
noreturn void abort(); 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)); int atexit(void (*)(void));
/* Not implemented.*/
int atoi(const char*); int atoi(const char*);
void free(void*);
/* Not implemented. */
char* getenv(const char*); 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 #ifdef __cplusplus
} }

View File

@ -3,11 +3,6 @@
#include <sys/syscall.h> #include <sys/syscall.h>
#include <unistd.h> #include <unistd.h>
#define noreturn __attribute__((noreturn))
#define maybe_unused __attribute__((maybe_unused))
#define unused __attribute__((unused))
extern "C" extern "C"
{ {
noreturn void abort() noreturn void abort()
@ -25,10 +20,12 @@ extern "C"
{ {
NOT_IMPLEMENTED("atexit"); NOT_IMPLEMENTED("atexit");
} }
int atoi(const char*) int atoi(const char*)
{ {
NOT_IMPLEMENTED("atoi"); NOT_IMPLEMENTED("atoi");
} }
char* getenv(const char*) char* getenv(const char*)
{ {
NOT_IMPLEMENTED("getenv"); NOT_IMPLEMENTED("getenv");