2d1505b51b5ad373b4aab9e068f96955cda9240f
[musl] / include / stdlib.h
1 #ifndef _STDLIB_H
2 #define _STDLIB_H
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 #include <features.h>
9
10 #undef NULL
11 #ifdef __cplusplus
12 #define NULL 0
13 #else
14 #define NULL ((void*)0)
15 #endif
16
17 #define __NEED_size_t
18 #define __NEED_wchar_t
19
20 #include <bits/alltypes.h>
21
22 int atoi (const char *);
23 long atol (const char *);
24 long long atoll (const char *);
25 double atof (const char *);
26
27 float strtof (const char *__restrict, char **__restrict);
28 double strtod (const char *__restrict, char **__restrict);
29 long double strtold (const char *__restrict, char **__restrict);
30
31 long strtol (const char *__restrict, char **__restrict, int);
32 unsigned long strtoul (const char *__restrict, char **__restrict, int);
33 long long strtoll (const char *__restrict, char **__restrict, int);
34 unsigned long long strtoull (const char *__restrict, char **__restrict, int);
35
36 int rand (void);
37 void srand (unsigned);
38
39 void *malloc (size_t);
40 void *calloc (size_t, size_t);
41 void *realloc (void *, size_t);
42 void free (void *);
43 void *aligned_alloc(size_t alignment, size_t size);
44
45 _Noreturn void abort (void);
46 int atexit (void (*) (void));
47 _Noreturn void exit (int);
48 _Noreturn void _Exit (int);
49 int at_quick_exit (void (*) (void));
50 _Noreturn void quick_exit (int);
51
52 char *getenv (const char *);
53
54 int system (const char *);
55
56 void *bsearch (const void *, const void *, size_t, size_t, int (*)(const void *, const void *));
57 void qsort (void *, size_t, size_t, int (*)(const void *, const void *));
58
59 int abs (int);
60 long labs (long);
61 long long llabs (long long);
62
63 typedef struct { int quot, rem; } div_t;
64 typedef struct { long quot, rem; } ldiv_t;
65 typedef struct { long long quot, rem; } lldiv_t;
66
67 div_t div (int, int);
68 ldiv_t ldiv (long, long);
69 lldiv_t lldiv (long long, long long);
70
71 int mblen (const char *, size_t);
72 int mbtowc (wchar_t *__restrict, const char *__restrict, size_t);
73 int wctomb (char *, wchar_t);
74 size_t mbstowcs (wchar_t *__restrict, const char *__restrict, size_t);
75 size_t wcstombs (char *__restrict, const wchar_t *__restrict, size_t);
76
77 #define EXIT_FAILURE 1
78 #define EXIT_SUCCESS 0
79
80 #define MB_CUR_MAX ((size_t)+4)
81
82 #define RAND_MAX (0x7fffffff)
83
84
85 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
86  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
87  || defined(_BSD_SOURCE)
88
89 #define WNOHANG    1
90 #define WUNTRACED  2
91
92 #define WEXITSTATUS(s) (((s) & 0xff00) >> 8)
93 #define WTERMSIG(s) ((s) & 0x7f)
94 #define WSTOPSIG(s) WEXITSTATUS(s)
95 #define WIFEXITED(s) (!WTERMSIG(s))
96 #define WIFSTOPPED(s) (((s) & 0xff) == 0x7f)
97 #define WIFSIGNALED(s) (((signed char) (((s) & 0x7f) + 1) >> 1) > 0)
98
99 int posix_memalign (void **, size_t, size_t);
100 int setenv (const char *, const char *, int);
101 int unsetenv (const char *);
102 int mkstemp (char *);
103 char *mkdtemp (char *);
104 int getsubopt (char **, char *const *, char **);
105 int rand_r (unsigned *);
106
107 #endif
108
109
110 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
111  || defined(_BSD_SOURCE)
112 char *realpath (const char *__restrict, char *__restrict);
113 long int random (void);
114 void srandom (unsigned int);
115 char *initstate (unsigned int, char *, size_t);
116 char *setstate (char *);
117 #endif
118
119 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
120 int putenv (char *);
121 int posix_openpt (int);
122 int grantpt (int);
123 int unlockpt (int);
124 char *ptsname (int);
125 char *l64a (long);
126 long a64l (const char *);
127 void setkey (const char *);
128 double drand48 (void);
129 double erand48 (unsigned short [3]);
130 long int lrand48 (void);
131 long int nrand48 (unsigned short [3]);
132 long mrand48 (void);
133 long jrand48 (unsigned short [3]);
134 void srand48 (long);
135 unsigned short *seed48 (unsigned short [3]);
136 void lcong48 (unsigned short [7]);
137 #endif
138
139 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
140 #include <alloca.h>
141 char *mktemp (char *);
142 void *valloc (size_t);
143 void *memalign(size_t, size_t);
144 #define WCOREDUMP(s) ((s) & 0x80)
145 #define WIFCONTINUED(s) ((s) == 0xffff)
146 #endif
147
148 #ifdef _GNU_SOURCE
149 int clearenv(void);
150 int ptsname_r(int, char *, size_t);
151 char *ecvt(double, int, int *, int *);
152 char *fcvt(double, int, int *, int *);
153 char *gcvt(double, int, char *);
154 #endif
155
156 #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
157 #define mkstemp64 mkstemp
158 #endif
159
160 #ifdef __cplusplus
161 }
162 #endif
163
164 #endif