2023-01-07 10:39:15 +00:00
|
|
|
/* stdlib.h: General utilities. */
|
2023-01-06 18:40:25 +00:00
|
|
|
|
2023-01-06 12:31:14 +00:00
|
|
|
#ifndef _STDLIB_H
|
|
|
|
#define _STDLIB_H
|
|
|
|
|
|
|
|
#include <bits/attrs.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
2023-01-06 18:40:25 +00:00
|
|
|
/* The result of a division operation on two integers. */
|
2023-01-06 12:31:14 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int quot;
|
|
|
|
int rem;
|
|
|
|
} div_t;
|
|
|
|
|
2023-01-06 18:40:25 +00:00
|
|
|
/* The result of a division operation on two long integers. */
|
2023-01-06 12:31:14 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
long quot;
|
|
|
|
long rem;
|
|
|
|
} ldiv_t;
|
|
|
|
|
2023-01-06 18:40:25 +00:00
|
|
|
/* The result of a division operation on two long long integers. */
|
2023-01-06 12:31:14 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
long long quot;
|
|
|
|
long long rem;
|
|
|
|
} lldiv_t;
|
|
|
|
|
2023-01-06 20:01:37 +00:00
|
|
|
#define MB_CUR_MAX 4
|
|
|
|
|
2023-01-06 12:31:14 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
2023-01-06 19:02:07 +00:00
|
|
|
/* Return the absolute value of an integer. */
|
2023-01-06 18:40:25 +00:00
|
|
|
int abs(int v);
|
|
|
|
|
2023-01-06 19:02:07 +00:00
|
|
|
/* Return the absolute value of a long integer. */
|
2023-01-06 18:40:25 +00:00
|
|
|
long labs(long v);
|
|
|
|
|
2023-01-06 19:02:07 +00:00
|
|
|
/* Return the absolute value of a long long integer. */
|
2023-01-06 18:40:25 +00:00
|
|
|
long long llabs(long long v);
|
2023-01-06 12:31:14 +00:00
|
|
|
|
2023-01-06 19:02:07 +00:00
|
|
|
/* Return the result of dividing two integers, including the remainder. */
|
2023-01-06 18:40:25 +00:00
|
|
|
div_t div(int num, int den);
|
|
|
|
|
2023-01-06 19:02:07 +00:00
|
|
|
/* Return the result of dividing two long integers, including the remainder. */
|
2023-01-06 12:31:14 +00:00
|
|
|
ldiv_t ldiv(long, long);
|
2023-01-06 18:40:25 +00:00
|
|
|
|
2023-01-06 19:02:07 +00:00
|
|
|
/* Return the result of dividing two long long integers, including the remainder. */
|
2023-01-06 12:31:14 +00:00
|
|
|
lldiv_t lldiv(long long, long long);
|
|
|
|
|
2023-01-13 19:00:20 +00:00
|
|
|
/* 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. */
|
2023-01-06 12:31:14 +00:00
|
|
|
void free(void*);
|
|
|
|
|
2023-01-06 19:02:07 +00:00
|
|
|
/* Abort the program without performing any normal cleanup. */
|
2023-01-06 12:31:14 +00:00
|
|
|
__noreturn void abort();
|
|
|
|
|
2023-01-06 19:02:07 +00:00
|
|
|
/* Register a handler to be run at normal program termination. */
|
2023-01-06 18:40:25 +00:00
|
|
|
int atexit(void (*func)(void));
|
|
|
|
|
2023-01-07 10:31:08 +00:00
|
|
|
/* Parse a decimal integer from a string. */
|
2023-01-06 18:40:25 +00:00
|
|
|
int atoi(const char* s);
|
|
|
|
|
2023-01-07 10:31:08 +00:00
|
|
|
/* Parse a decimal integer from a string. */
|
2023-01-06 18:40:25 +00:00
|
|
|
long atol(const char* s);
|
|
|
|
|
2023-01-07 10:31:08 +00:00
|
|
|
/* Parse a decimal integer from a string. */
|
2023-01-06 18:40:25 +00:00
|
|
|
long long atoll(const char* s);
|
2023-01-06 12:31:14 +00:00
|
|
|
|
|
|
|
double atof(const char*);
|
|
|
|
|
|
|
|
double strtod(const char*, char**);
|
|
|
|
|
2023-01-06 19:02:07 +00:00
|
|
|
/* Parse an integer of the specified base from a string, storing the first non-number character in endptr if
|
2023-01-06 18:40:25 +00:00
|
|
|
* nonnull. */
|
|
|
|
long strtol(const char* str, char** endptr, int base);
|
|
|
|
|
2023-01-06 19:02:07 +00:00
|
|
|
/* Parse an unsigned integer of the specified base from a string, storing the first non-number character in
|
2023-01-06 18:40:25 +00:00
|
|
|
* endptr if nonnull. */
|
|
|
|
unsigned long strtoul(const char* str, char** endptr, int base);
|
2023-01-06 12:31:14 +00:00
|
|
|
|
|
|
|
int rand();
|
|
|
|
void srand(int);
|
|
|
|
|
2023-01-06 19:02:07 +00:00
|
|
|
/* Exit the program normally, performing any registered cleanup actions. */
|
2023-03-23 21:25:56 +00:00
|
|
|
__noreturn void exit(int status);
|
2023-01-06 12:31:14 +00:00
|
|
|
|
2023-01-06 19:02:07 +00:00
|
|
|
/* Exit the program abnormally, without performing any registered cleanup actions. */
|
2023-03-23 21:25:56 +00:00
|
|
|
__noreturn void _Exit(int status);
|
2023-01-06 18:40:25 +00:00
|
|
|
|
2023-01-06 12:31:14 +00:00
|
|
|
int system(const char*);
|
|
|
|
|
2023-04-07 13:03:38 +00:00
|
|
|
/* Get the value of an environment variable. */
|
|
|
|
char* getenv(const char* key);
|
2023-01-06 12:31:14 +00:00
|
|
|
|
|
|
|
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*));
|
|
|
|
|
2023-01-06 20:01:37 +00:00
|
|
|
/* Convert a multibyte character string to a wide character string. */
|
|
|
|
size_t mbstowcs(wchar_t* buf, const char* src, size_t max);
|
|
|
|
|
2023-01-14 10:59:08 +00:00
|
|
|
/* Convert a wide character string to a multibyte character string. */
|
|
|
|
size_t wcstombs(char* buf, const wchar_t* src, size_t max);
|
|
|
|
|
2023-01-06 12:31:14 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|