138 lines
4.5 KiB
C
138 lines
4.5 KiB
C
#ifndef _STDLIB_H
|
|
#define _STDLIB_H
|
|
|
|
#include <bits/macros.h>
|
|
#include <limits.h>
|
|
#include <stddef.h>
|
|
|
|
#define EXIT_SUCCESS 0 // Value to use when calling exit() to represent successful execution.
|
|
#define EXIT_FAILURE 1 // Value to use when calling exit() to represent failed execution.
|
|
|
|
#define RAND_MAX INT_MAX // Maximum number returned by rand().
|
|
|
|
// Return type for an integer division.
|
|
typedef struct
|
|
{
|
|
int quot;
|
|
int rem;
|
|
} div_t;
|
|
|
|
// Return type for a long integer division.
|
|
typedef struct
|
|
{
|
|
long quot;
|
|
long rem;
|
|
} ldiv_t;
|
|
|
|
// Return type for a long integer division.
|
|
typedef struct
|
|
{
|
|
long long quot;
|
|
long long rem;
|
|
} lldiv_t;
|
|
|
|
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
/* Aborts the program. */
|
|
__lc_noreturn void abort(void);
|
|
|
|
/* Normally exits the program with the specified status code. */
|
|
__lc_noreturn void exit(int status);
|
|
|
|
/* Abnormally exits the program with the specified status code. */
|
|
__lc_noreturn void _Exit(int status);
|
|
|
|
/* Registers a handler function to be run at normal program termination. */
|
|
int atexit(void (*handler)(void));
|
|
|
|
/* Returns a floating point number parsed from the string str. */
|
|
float atof(const char* str);
|
|
|
|
/* Returns an integer (of type int) parsed from the string str. */
|
|
int atoi(const char* str);
|
|
|
|
/* Returns an integer (of type long) parsed from the string str. */
|
|
long atol(const char* str);
|
|
|
|
/* Returns an integer (of type long long) parsed from the string str. */
|
|
long long atoll(const char* str);
|
|
|
|
/* Returns an integer (of type unsigned long) parsed from the string str. */
|
|
unsigned long strtoul(const char* str, char** endptr, int base);
|
|
|
|
double strtod(const char* str, char** endptr); // Not implemented.
|
|
|
|
/* Returns an integer (of type long) parsed from the string str. */
|
|
long strtol(const char* str, char** endptr, int base);
|
|
|
|
/* Not implemented. */
|
|
char* getenv(const char*);
|
|
|
|
/* 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);
|
|
|
|
/* Returns a random number. */
|
|
int rand(void);
|
|
|
|
/* Seeds the random number generator with the specified seed. */
|
|
void srand(unsigned int seed);
|
|
|
|
/* Returns the absolute value of an integer. */
|
|
int abs(int val);
|
|
|
|
/* Returns the absolute value of an integer. */
|
|
long labs(long val);
|
|
|
|
/* Returns the absolute value of an integer. */
|
|
long long llabs(long long val);
|
|
|
|
/* Returns the result of dividing a by b. */
|
|
div_t div(int a, int b);
|
|
|
|
/* Returns the result of dividing a by b. */
|
|
ldiv_t ldiv(long a, long b);
|
|
|
|
/* Returns the result of dividing a by b. */
|
|
lldiv_t lldiv(long long a, long long b);
|
|
|
|
/* Runs a shell command. */
|
|
int system(const char* command);
|
|
|
|
/* Sorts the array pointed to by base of nmemb items of the specified size using the comparison function compar. */
|
|
void qsort(void* base, size_t nmemb, size_t size, int (*compar)(const void*, const void*));
|
|
|
|
/* Searches the sorted array base of nmemb items of the specified size for the given key using the comparison
|
|
* function compar. */
|
|
void* bsearch(const void* key, const void* base, size_t nmemb, size_t size,
|
|
int (*compar)(const void*, const void*));
|
|
|
|
size_t mbstowcs(wchar_t* dest, const char* src,
|
|
size_t n); // Not implemented.
|
|
|
|
/* Generate a unique filename from the template string str. The last 6 bytes of str must be 'XXXXXX', and they will
|
|
* be replaced with random characters. This function is deprecated due to race conditions; between the name being
|
|
* generated and creating a file with that name, that filename could have already been used. */
|
|
__lc_is_deprecated char* mktemp(char* str);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif |