1#ifndef _STDLIB_H
  2#define _STDLIB_H
  3
  4#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
  5#else
  6#include <__functions_malloc.h>
  7#include <__header_stdlib.h>
  8#endif
  9#ifdef __cplusplus
 10extern "C" {
 11#endif
 12
 13#include <features.h>
 14
 15#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */
 16#if __cplusplus >= 201103L
 17#define NULL nullptr
 18#elif defined(__cplusplus)
 19#define NULL 0L
 20#else
 21#define NULL ((void*)0)
 22#endif
 23#else
 24#define __need_NULL
 25#include <stddef.h>
 26#endif
 27
 28#define __NEED_size_t
 29#define __NEED_wchar_t
 30
 31#include <bits/alltypes.h>
 32
 33int atoi (const char *);
 34long atol (const char *);
 35long long atoll (const char *);
 36double atof (const char *);
 37
 38float strtof (const char *__restrict, char **__restrict);
 39double strtod (const char *__restrict, char **__restrict);
 40long double strtold (const char *__restrict, char **__restrict);
 41
 42long strtol (const char *__restrict, char **__restrict, int);
 43unsigned long strtoul (const char *__restrict, char **__restrict, int);
 44long long strtoll (const char *__restrict, char **__restrict, int);
 45unsigned long long strtoull (const char *__restrict, char **__restrict, int);
 46
 47int rand (void);
 48void srand (unsigned);
 49
 50#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
 51void *malloc (size_t);
 52void *calloc (size_t, size_t);
 53void *realloc (void *, size_t);
 54void free (void *);
 55#endif
 56void *aligned_alloc(size_t, size_t);
 57
 58_Noreturn void abort (void);
 59int atexit (void (*) (void));
 60_Noreturn void exit (int);
 61_Noreturn void _Exit (int);
 62int at_quick_exit (void (*) (void));
 63_Noreturn void quick_exit (int);
 64
 65char *getenv (const char *);
 66
 67int system (const char *);
 68
 69void *bsearch (const void *, const void *, size_t, size_t, int (*)(const void *, const void *));
 70void qsort (void *, size_t, size_t, int (*)(const void *, const void *));
 71
 72int abs (int);
 73long labs (long);
 74long long llabs (long long);
 75
 76typedef struct { int quot, rem; } div_t;
 77typedef struct { long quot, rem; } ldiv_t;
 78typedef struct { long long quot, rem; } lldiv_t;
 79
 80div_t div (int, int);
 81ldiv_t ldiv (long, long);
 82lldiv_t lldiv (long long, long long);
 83
 84int mblen (const char *, size_t);
 85int mbtowc (wchar_t *__restrict, const char *__restrict, size_t);
 86int wctomb (char *, wchar_t);
 87size_t mbstowcs (wchar_t *__restrict, const char *__restrict, size_t);
 88size_t wcstombs (char *__restrict, const wchar_t *__restrict, size_t);
 89
 90#define EXIT_FAILURE 1
 91#define EXIT_SUCCESS 0
 92
 93size_t __ctype_get_mb_cur_max(void);
 94#define MB_CUR_MAX (__ctype_get_mb_cur_max())
 95
 96#define RAND_MAX (0x7fffffff)
 97
 98
 99#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
100 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
101 || defined(_BSD_SOURCE)
102
103#ifdef __wasilibc_unmodified_upstream /* WASI has no wait */
104#define WNOHANG    1
105#define WUNTRACED  2
106
107#define WEXITSTATUS(s) (((s) & 0xff00) >> 8)
108#define WTERMSIG(s) ((s) & 0x7f)
109#define WSTOPSIG(s) WEXITSTATUS(s)
110#define WIFEXITED(s) (!WTERMSIG(s))
111#define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001U)>>8) > 0x7f00)
112#define WIFSIGNALED(s) (((s)&0xffff)-1U < 0xffu)
113#endif
114
115int posix_memalign (void **, size_t, size_t);
116int setenv (const char *, const char *, int);
117int unsetenv (const char *);
118#ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */
119int mkstemp (char *);
120int mkostemp (char *, int);
121char *mkdtemp (char *);
122#endif
123int getsubopt (char **, char *const *, char **);
124int rand_r (unsigned *);
125
126#endif
127
128
129#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
130 || defined(_BSD_SOURCE)
131char *realpath (const char *__restrict, char *__restrict);
132long int random (void);
133void srandom (unsigned int);
134char *initstate (unsigned int, char *, size_t);
135char *setstate (char *);
136int putenv (char *);
137#ifdef __wasilibc_unmodified_upstream /* WASI has no pseudo-terminals */
138int posix_openpt (int);
139int grantpt (int);
140int unlockpt (int);
141char *ptsname (int);
142#endif
143char *l64a (long);
144long a64l (const char *);
145void setkey (const char *);
146double drand48 (void);
147double erand48 (unsigned short [3]);
148long int lrand48 (void);
149long int nrand48 (unsigned short [3]);
150long mrand48 (void);
151long jrand48 (unsigned short [3]);
152void srand48 (long);
153unsigned short *seed48 (unsigned short [3]);
154void lcong48 (unsigned short [7]);
155#endif
156
157#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
158#include <alloca.h>
159#ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */
160char *mktemp (char *);
161int mkstemps (char *, int);
162int mkostemps (char *, int, int);
163#endif
164#ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */
165void *valloc (size_t);
166void *memalign(size_t, size_t);
167int getloadavg(double *, int);
168#endif
169int clearenv(void);
170#ifdef __wasilibc_unmodified_upstream /* WASI has no wait */
171#define WCOREDUMP(s) ((s) & 0x80)
172#define WIFCONTINUED(s) ((s) == 0xffff)
173void *reallocarray (void *, size_t, size_t);
174void qsort_r (void *, size_t, size_t, int (*)(const void *, const void *, void *), void *);
175#endif
176#endif
177
178#ifdef _GNU_SOURCE
179#ifdef __wasilibc_unmodified_upstream /* WASI has no pseudo-terminals */
180int ptsname_r(int, char *, size_t);
181#endif
182char *ecvt(double, int, int *, int *);
183char *fcvt(double, int, int *, int *);
184char *gcvt(double, int, char *);
185char *secure_getenv(const char *);
186struct __locale_struct;
187float strtof_l(const char *__restrict, char **__restrict, struct __locale_struct *);
188double strtod_l(const char *__restrict, char **__restrict, struct __locale_struct *);
189long double strtold_l(const char *__restrict, char **__restrict, struct __locale_struct *);
190#endif
191
192#ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */
193#if defined(_LARGEFILE64_SOURCE)
194#define mkstemp64 mkstemp
195#define mkostemp64 mkostemp
196#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
197#define mkstemps64 mkstemps
198#define mkostemps64 mkostemps
199#endif
200#endif
201#endif
202
203#ifdef __wasilibc_unmodified_upstream /* Declare arc4random functions */
204#else
205#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
206#include <stdint.h>
207uint32_t arc4random(void);
208void arc4random_buf(void *, size_t);
209uint32_t arc4random_uniform(uint32_t);
210#endif
211#endif
212
213#ifdef __cplusplus
214}
215#endif
216
217#endif