stdlib.h (2758B)
1 #ifndef STDLIB_H 2 #define STDLIB_H 3 4 #include <stddef.h> 5 #include <alloca.h> 6 7 #define RAND_MAX 2147483646 // rand() returns values mod 2^31-1 8 9 10 typedef struct { 11 int quot; // quotient 12 int rem; // remainder 13 } div_t; 14 typedef struct { 15 long quot; // quotient 16 long rem; // remainder 17 } ldiv_t; 18 typedef struct { 19 long long quot; // quotient 20 long long rem; // remainder 21 } lldiv_t; 22 23 24 // Process exit 25 void exit(int status); 26 void abort(void); 27 int atexit(void (*func)(void)); 28 29 // Memory allocation 30 void *malloc(size_t size); 31 void *calloc(size_t nmemb, size_t size); 32 void *realloc(void *ptr, size_t size); 33 void *memalign(size_t boundary, size_t size); 34 void free(void *ptr); 35 36 // Numeric functions 37 int abs(int i); 38 long labs(long i); 39 long long llabs(long long i); 40 41 div_t div(int numer, int denom); 42 ldiv_t ldiv(long numer, long denom); 43 lldiv_t lldiv(long long numer, long long denom); 44 45 // Numeric conversion 46 int atoi(const char *str); 47 long atol(const char *str); 48 long long atoll(const char *str); 49 double atof(const char *str); 50 long strtol(const char *__restrict str, 51 char **__restrict endptr, int base); 52 long long strtoll(const char *__restrict str, 53 char **__restrict endptr, int base); 54 unsigned long strtoul(const char *__restrict str, 55 char **__restrict endptr, int base); 56 unsigned long long strtoull(const char *__restrict str, 57 char **__restrict endptr, int base); 58 float strtof(const char *__restrict nptr, char **__restrict endptr);; 59 double strtod(const char *__restrict nptr, char **__restrict endptr); 60 61 // Multibyte string conversion functions 62 int mblen(const char *, size_t); 63 int mbtowc(wchar_t *__restrict, const char *__restrict, size_t); 64 size_t mbstowcs(wchar_t *__restrict, const char *__restrict, size_t); 65 66 // Sorting and searching 67 void qsort(void *base, size_t nelt, size_t eltsize, 68 int (*cmp)(const void *a, const void *b)); 69 void *bsearch(const void *key, const void *base, size_t nelt, 70 size_t eltsize, int (*cmp)(const void *a, const void *b)); 71 72 // Environment variables 73 char *getenv(const char *name); 74 int setenv(const char *envname, const char *envval, int overwrite); 75 int unsetenv(const char *name); 76 int putenv(const char *string); 77 78 // Temporary files 79 char *mktemp(char *tmpl); 80 int mkstemp(char *tmpl); 81 82 // Random numbers 83 int rand(void); 84 int rand_r(unsigned *seed); 85 void srand(unsigned seed); 86 87 double drand48(void); 88 long lrand48(void); 89 long mrand48(void); 90 double erand48(unsigned short xsubi[3]); 91 long nrand48(unsigned short xsubi[3]); 92 long jrand48(unsigned short xsubi[3]); 93 void srand48(long seedval); 94 void lcong48(unsigned short param[7]); 95 unsigned short *seed48(unsigned short seed16v[3]); 96 97 // System commands 98 int system(const char *command); 99 100 void abort(void); 101 102 #define EXIT_SUCCESS 0 103 #define EXIT_FAILURE 1 104 105 #endif // STDLIB_H