libc: header documentation for supported functions
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-01-06 20:02:07 +01:00
parent c3653cd4e6
commit 367a2ce521
Signed by: apio
GPG Key ID: B8A7D06E42258954
5 changed files with 49 additions and 17 deletions

View File

@ -1,6 +1,9 @@
/* errno.h: Error management header. */
#ifndef _ERRNO_H #ifndef _ERRNO_H
#define _ERRNO_H #define _ERRNO_H
/* The last error encountered after a call to a system or library function. */
extern int errno; extern int errno;
#include <luna/SystemError.h> #include <luna/SystemError.h>

View File

@ -1,3 +1,5 @@
/* stdio.h: Standard input/output header. */
#ifndef _STDIO_H #ifndef _STDIO_H
#define _STDIO_H #define _STDIO_H
@ -36,7 +38,8 @@ extern "C"
int vfprintf(FILE*, const char*, va_list); int vfprintf(FILE*, const char*, va_list);
int sprintf(char*, const char*, ...); int sprintf(char*, const char*, ...);
int console_print(const char*); /* Output a message to the console. */
int console_print(const char* msg);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -32,22 +32,22 @@ extern "C"
{ {
#endif #endif
/* Returns the absolute value of v. */ /* Return the absolute value of an integer. */
int abs(int v); int abs(int v);
/* Returns the absolute value of v. */ /* Return the absolute value of a long integer. */
long labs(long v); long labs(long v);
/* Returns the absolute value of v. */ /* Return the absolute value of a long long integer. */
long long llabs(long long v); long long llabs(long long v);
/* Returns the result of dividing num by den, including the remainder. */ /* Return the result of dividing two integers, including the remainder. */
div_t div(int num, int den); div_t div(int num, int den);
/* Returns the result of dividing num by den, including the remainder. */ /* Return the result of dividing two long integers, including the remainder. */
ldiv_t ldiv(long, long); ldiv_t ldiv(long, long);
/* Returns the result of dividing num by den, including the remainder. */ /* Return the result of dividing two long long integers, including the remainder. */
lldiv_t lldiv(long long, long long); lldiv_t lldiv(long long, long long);
void* malloc(size_t); void* malloc(size_t);
@ -55,40 +55,40 @@ extern "C"
void* realloc(void*, size_t); void* realloc(void*, size_t);
void free(void*); void free(void*);
/* Aborts the program without performing any normal cleanup. */ /* Abort the program without performing any normal cleanup. */
__noreturn void abort(); __noreturn void abort();
/* Registers a handler to be run at normal program termination. */ /* Register a handler to be run at normal program termination. */
int atexit(void (*func)(void)); int atexit(void (*func)(void));
/* Parses a decimal integer from the provided string. */ /* Parse a decimal integer from the a string. */
int atoi(const char* s); int atoi(const char* s);
/* Parses a decimal integer from the provided string. */ /* Parse a decimal integer from the a string. */
long atol(const char* s); long atol(const char* s);
/* Parses a decimal integer from the provided string. */ /* Parse a decimal integer from the a string. */
long long atoll(const char* s); long long atoll(const char* s);
double atof(const char*); double atof(const char*);
double strtod(const char*, char**); double strtod(const char*, char**);
/* Parses an integer of the specified base from the string str, storing the first non-number character in endptr if /* Parse an integer of the specified base from a string, storing the first non-number character in endptr if
* nonnull. */ * nonnull. */
long strtol(const char* str, char** endptr, int base); long strtol(const char* str, char** endptr, int base);
/* Parses an unsigned integer of the specified base from the string str, storing the first non-number character in /* Parse an unsigned integer of the specified base from a string, storing the first non-number character in
* endptr if nonnull. */ * endptr if nonnull. */
unsigned long strtoul(const char* str, char** endptr, int base); unsigned long strtoul(const char* str, char** endptr, int base);
int rand(); int rand();
void srand(int); void srand(int);
/* Exits the program normally, performing any registered cleanup actions. */ /* Exit the program normally, performing any registered cleanup actions. */
__noreturn void exit(int); __noreturn void exit(int);
/* Exits the program abnormally, without performing any registered cleanup actions. */ /* Exit the program abnormally, without performing any registered cleanup actions. */
__noreturn void _Exit(int); __noreturn void _Exit(int);
int system(const char*); int system(const char*);

View File

@ -1,3 +1,5 @@
/* string.h: String manipulation header. */
#ifndef _STRING_H #ifndef _STRING_H
#define _STRING_H #define _STRING_H
@ -9,19 +11,37 @@ extern "C"
{ {
#endif #endif
/* Copy n bytes of memory from src to dest. */
void* memcpy(void* dest, const void* src, size_t n); void* memcpy(void* dest, const void* src, size_t n);
/* Set n bytes of memory to the character c. */
void* memset(void* buf, int c, size_t n); void* memset(void* buf, int c, size_t n);
/* Compare n bytes of two memory locations. */
int memcmp(const void* a, const void* b, size_t n); int memcmp(const void* a, const void* b, size_t n);
/* Copy n bytes of memory from src to dest, where src and dest may overlap. */
void* memmove(void* dest, const void* src, size_t n); void* memmove(void* dest, const void* src, size_t n);
/* Return the length of a null-terminated string. */
size_t strlen(const char* str); size_t strlen(const char* str);
/* Compare two null-terminated strings. */
int strcmp(const char* a, const char* b); int strcmp(const char* a, const char* b);
/* Copy the null-terminated string src into dest. Should be avoided to prevent buffer overflow attacks. */
__deprecated char* strcpy(char* dest, const char* src); __deprecated char* strcpy(char* dest, const char* src);
/* Concatenate the null-terminated string src onto dest. Should be avoided to prevent buffer overflow attacks. */
__deprecated char* strcat(char* dest, const char* src); __deprecated char* strcat(char* dest, const char* src);
/* Return a pointer to the first occurrence of the character c in str, or NULL if it could not be found. */
char* strchr(const char* str, int c); char* strchr(const char* str, int c);
/* Return a heap-allocated copy of a string. */
char* strdup(const char* str); char* strdup(const char* str);
/* Return the human-readable description of an error number. */
char* strerror(int errnum); char* strerror(int errnum);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -1,6 +1,11 @@
/* unistd.h: POSIX constants and functions. */
#ifndef _UNISTD_H #ifndef _UNISTD_H
#define _UNISTD_H #define _UNISTD_H
#define __need_NULL
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <sys/types.h> #include <sys/types.h>
@ -16,7 +21,8 @@ extern "C"
int execve(const char*, char* const*, char* const*); int execve(const char*, char* const*, char* const*);
int execvp(const char*, char* const*); int execvp(const char*, char* const*);
long syscall(long, ...); /* Calls the operating system kernel for a specific service. */
long syscall(long num, ...);
#ifdef __cplusplus #ifdef __cplusplus
} }