| 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 |
| 10 |
extern "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 |
|
| 33 |
int atoi (const char *); |
| 34 |
long atol (const char *); |
| 35 |
long long atoll (const char *); |
| 36 |
double atof (const char *); |
| 37 |
|
| 38 |
float strtof (const char *__restrict, char **__restrict); |
| 39 |
double strtod (const char *__restrict, char **__restrict); |
| 40 |
long double strtold (const char *__restrict, char **__restrict); |
| 41 |
|
| 42 |
long strtol (const char *__restrict, char **__restrict, int); |
| 43 |
unsigned long strtoul (const char *__restrict, char **__restrict, int); |
| 44 |
long long strtoll (const char *__restrict, char **__restrict, int); |
| 45 |
unsigned long long strtoull (const char *__restrict, char **__restrict, int); |
| 46 |
|
| 47 |
int rand (void); |
| 48 |
void srand (unsigned); |
| 49 |
|
| 50 |
#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ |
| 51 |
void *malloc (size_t); |
| 52 |
void *calloc (size_t, size_t); |
| 53 |
void *realloc (void *, size_t); |
| 54 |
void free (void *); |
| 55 |
#endif |
| 56 |
void *aligned_alloc(size_t, size_t); |
| 57 |
|
| 58 |
_Noreturn void abort (void); |
| 59 |
int atexit (void (*) (void)); |
| 60 |
_Noreturn void exit (int); |
| 61 |
_Noreturn void _Exit (int); |
| 62 |
int at_quick_exit (void (*) (void)); |
| 63 |
_Noreturn void quick_exit (int); |
| 64 |
|
| 65 |
char *getenv (const char *); |
| 66 |
|
| 67 |
int system (const char *); |
| 68 |
|
| 69 |
void *bsearch (const void *, const void *, size_t, size_t, int (*)(const void *, const void *)); |
| 70 |
void qsort (void *, size_t, size_t, int (*)(const void *, const void *)); |
| 71 |
|
| 72 |
int abs (int); |
| 73 |
long labs (long); |
| 74 |
long long llabs (long long); |
| 75 |
|
| 76 |
typedef struct { int quot, rem; } div_t; |
| 77 |
typedef struct { long quot, rem; } ldiv_t; |
| 78 |
typedef struct { long long quot, rem; } lldiv_t; |
| 79 |
|
| 80 |
div_t div (int, int); |
| 81 |
ldiv_t ldiv (long, long); |
| 82 |
lldiv_t lldiv (long long, long long); |
| 83 |
|
| 84 |
int mblen (const char *, size_t); |
| 85 |
int mbtowc (wchar_t *__restrict, const char *__restrict, size_t); |
| 86 |
int wctomb (char *, wchar_t); |
| 87 |
size_t mbstowcs (wchar_t *__restrict, const char *__restrict, size_t); |
| 88 |
size_t wcstombs (char *__restrict, const wchar_t *__restrict, size_t); |
| 89 |
|
| 90 |
#define EXIT_FAILURE 1 |
| 91 |
#define EXIT_SUCCESS 0 |
| 92 |
|
| 93 |
size_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 |
|
| 115 |
int posix_memalign (void **, size_t, size_t); |
| 116 |
int setenv (const char *, const char *, int); |
| 117 |
int unsetenv (const char *); |
| 118 |
#ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ |
| 119 |
int mkstemp (char *); |
| 120 |
int mkostemp (char *, int); |
| 121 |
char *mkdtemp (char *); |
| 122 |
#endif |
| 123 |
int getsubopt (char **, char *const *, char **); |
| 124 |
int rand_r (unsigned *); |
| 125 |
|
| 126 |
#endif |
| 127 |
|
| 128 |
|
| 129 |
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ |
| 130 |
|| defined(_BSD_SOURCE) |
| 131 |
char *realpath (const char *__restrict, char *__restrict); |
| 132 |
long int random (void); |
| 133 |
void srandom (unsigned int); |
| 134 |
char *initstate (unsigned int, char *, size_t); |
| 135 |
char *setstate (char *); |
| 136 |
int putenv (char *); |
| 137 |
#ifdef __wasilibc_unmodified_upstream /* WASI has no pseudo-terminals */ |
| 138 |
int posix_openpt (int); |
| 139 |
int grantpt (int); |
| 140 |
int unlockpt (int); |
| 141 |
char *ptsname (int); |
| 142 |
#endif |
| 143 |
char *l64a (long); |
| 144 |
long a64l (const char *); |
| 145 |
void setkey (const char *); |
| 146 |
double drand48 (void); |
| 147 |
double erand48 (unsigned short [3]); |
| 148 |
long int lrand48 (void); |
| 149 |
long int nrand48 (unsigned short [3]); |
| 150 |
long mrand48 (void); |
| 151 |
long jrand48 (unsigned short [3]); |
| 152 |
void srand48 (long); |
| 153 |
unsigned short *seed48 (unsigned short [3]); |
| 154 |
void 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 */ |
| 160 |
char *mktemp (char *); |
| 161 |
int mkstemps (char *, int); |
| 162 |
int mkostemps (char *, int, int); |
| 163 |
#endif |
| 164 |
#ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ |
| 165 |
void *valloc (size_t); |
| 166 |
void *memalign(size_t, size_t); |
| 167 |
int getloadavg(double *, int); |
| 168 |
#endif |
| 169 |
int clearenv(void); |
| 170 |
#ifdef __wasilibc_unmodified_upstream /* WASI has no wait */ |
| 171 |
#define WCOREDUMP(s) ((s) & 0x80) |
| 172 |
#define WIFCONTINUED(s) ((s) == 0xffff) |
| 173 |
void *reallocarray (void *, size_t, size_t); |
| 174 |
void 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 */ |
| 180 |
int ptsname_r(int, char *, size_t); |
| 181 |
#endif |
| 182 |
char *ecvt(double, int, int *, int *); |
| 183 |
char *fcvt(double, int, int *, int *); |
| 184 |
char *gcvt(double, int, char *); |
| 185 |
char *secure_getenv(const char *); |
| 186 |
struct __locale_struct; |
| 187 |
float strtof_l(const char *__restrict, char **__restrict, struct __locale_struct *); |
| 188 |
double strtod_l(const char *__restrict, char **__restrict, struct __locale_struct *); |
| 189 |
long 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> |
| 207 |
uint32_t arc4random(void); |
| 208 |
void arc4random_buf(void *, size_t); |
| 209 |
uint32_t arc4random_uniform(uint32_t); |
| 210 |
#endif |
| 211 |
#endif |
| 212 |
|
| 213 |
#ifdef __cplusplus |
| 214 |
} |
| 215 |
#endif |
| 216 |
|
| 217 |
#endif |