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