Luna/libc/include/stdlib.h

122 lines
3.2 KiB
C

/* stdlib.h: General utilities. */
#ifndef _STDLIB_H
#define _STDLIB_H
#include <bits/attrs.h>
#include <stddef.h>
/* The result of a division operation on two integers. */
typedef struct
{
int quot;
int rem;
} div_t;
/* The result of a division operation on two long integers. */
typedef struct
{
long quot;
long rem;
} ldiv_t;
/* The result of a division operation on two long long integers. */
typedef struct
{
long long quot;
long long rem;
} lldiv_t;
#define MB_CUR_MAX 4
#ifdef __cplusplus
extern "C"
{
#endif
/* Return the absolute value of an integer. */
int abs(int v);
/* Return the absolute value of a long integer. */
long labs(long v);
/* Return the absolute value of a long long integer. */
long long llabs(long long v);
/* Return the result of dividing two integers, including the remainder. */
div_t div(int num, int den);
/* Return the result of dividing two long integers, including the remainder. */
ldiv_t ldiv(long, long);
/* Return the result of dividing two long long integers, including the remainder. */
lldiv_t lldiv(long long, long long);
/* Allocate heap memory. */
void* malloc(size_t size);
/* Allocate zero-initialized heap memory. */
void* calloc(size_t nmemb, size_t size);
/* Resize allocated heap memory. */
void* realloc(void* ptr, size_t size);
/* Free heap memory. */
void free(void*);
/* Abort the program without performing any normal cleanup. */
__noreturn void abort();
/* Register a handler to be run at normal program termination. */
int atexit(void (*func)(void));
/* Parse a decimal integer from a string. */
int atoi(const char* s);
/* Parse a decimal integer from a string. */
long atol(const char* s);
/* Parse a decimal integer from a string. */
long long atoll(const char* s);
double atof(const char*);
double strtod(const char*, char**);
/* Parse an integer of the specified base from a string, storing the first non-number character in endptr if
* nonnull. */
long strtol(const char* str, char** endptr, int base);
/* Parse an unsigned integer of the specified base from a string, storing the first non-number character in
* endptr if nonnull. */
unsigned long strtoul(const char* str, char** endptr, int base);
int rand();
void srand(int);
/* Exit the program normally, performing any registered cleanup actions. */
__noreturn void exit(int status);
/* Exit the program abnormally, without performing any registered cleanup actions. */
__noreturn void _Exit(int status);
int system(const char*);
/* Get the value of an environment variable. */
char* getenv(const char* key);
void qsort(void*, size_t, size_t, int (*)(const void*, const void*));
void* bsearch(const void*, const void*, size_t, size_t, int (*)(const void*, const void*));
/* Convert a multibyte character string to a wide character string. */
size_t mbstowcs(wchar_t* buf, const char* src, size_t max);
/* Convert a wide character string to a multibyte character string. */
size_t wcstombs(char* buf, const wchar_t* src, size_t max);
#ifdef __cplusplus
}
#endif
#endif