stdlib.h 4.1 KB
Newer Older
R
Rich Felker 已提交
1 2 3 4 5 6 7
#ifndef _STDLIB_H
#define _STDLIB_H

#ifdef __cplusplus
extern "C" {
#endif

8
#include <features.h>
9

R
Rich Felker 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#undef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void*)0)
#endif

#define __NEED_size_t
#define __NEED_wchar_t

#include <bits/alltypes.h>

int atoi (const char *);
long atol (const char *);
long long atoll (const char *);
double atof (const char *);

27 28 29
float strtof (const char *__restrict, char **__restrict);
double strtod (const char *__restrict, char **__restrict);
long double strtold (const char *__restrict, char **__restrict);
R
Rich Felker 已提交
30

31 32 33 34
long strtol (const char *__restrict, char **__restrict, int);
unsigned long strtoul (const char *__restrict, char **__restrict, int);
long long strtoll (const char *__restrict, char **__restrict, int);
unsigned long long strtoull (const char *__restrict, char **__restrict, int);
R
Rich Felker 已提交
35 36 37 38 39 40 41 42

int rand (void);
void srand (unsigned);

void *malloc (size_t);
void *calloc (size_t, size_t);
void *realloc (void *, size_t);
void free (void *);
43
void *aligned_alloc(size_t alignment, size_t size);
R
Rich Felker 已提交
44

45
_Noreturn void abort (void);
R
Rich Felker 已提交
46
int atexit (void (*) (void));
47 48
_Noreturn void exit (int);
_Noreturn void _Exit (int);
49
int at_quick_exit (void (*) (void));
50
_Noreturn void quick_exit (int);
R
Rich Felker 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

char *getenv (const char *);

int system (const char *);

void *bsearch (const void *, const void *, size_t, size_t, int (*)(const void *, const void *));
void qsort (void *, size_t, size_t, int (*)(const void *, const void *));

int abs (int);
long labs (long);
long long llabs (long long);

typedef struct { int quot, rem; } div_t;
typedef struct { long quot, rem; } ldiv_t;
typedef struct { long long quot, rem; } lldiv_t;

67 68 69
div_t div (int, int);
ldiv_t ldiv (long, long);
lldiv_t lldiv (long long, long long);
R
Rich Felker 已提交
70 71

int mblen (const char *, size_t);
72
int mbtowc (wchar_t *__restrict, const char *__restrict, size_t);
R
Rich Felker 已提交
73
int wctomb (char *, wchar_t);
74 75
size_t mbstowcs (wchar_t *__restrict, const char *__restrict, size_t);
size_t wcstombs (char *__restrict, const wchar_t *__restrict, size_t);
R
Rich Felker 已提交
76

77 78 79
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0

80
#define MB_CUR_MAX ((size_t)+4)
81 82 83 84 85

#define RAND_MAX (0x7fffffff)


#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
86 87
 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
 || defined(_BSD_SOURCE)
88

89 90 91
#define WNOHANG    1
#define WUNTRACED  2

92 93 94 95 96 97
#define WEXITSTATUS(s) (((s) & 0xff00) >> 8)
#define WTERMSIG(s) ((s) & 0x7f)
#define WSTOPSIG(s) WEXITSTATUS(s)
#define WIFEXITED(s) (!WTERMSIG(s))
#define WIFSTOPPED(s) (((s) & 0xff) == 0x7f)
#define WIFSIGNALED(s) (((signed char) (((s) & 0x7f) + 1) >> 1) > 0)
98 99 100 101 102 103

int posix_memalign (void **, size_t, size_t);
int setenv (const char *, const char *, int);
int unsetenv (const char *);
int mkstemp (char *);
char *mkdtemp (char *);
R
Rich Felker 已提交
104
int getsubopt (char **, char *const *, char **);
105
int rand_r (unsigned *);
R
Rich Felker 已提交
106

107
#endif
R
Rich Felker 已提交
108

109

110 111
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
 || defined(_BSD_SOURCE)
112
char *realpath (const char *__restrict, char *__restrict);
113 114 115 116 117 118
long int random (void);
void srandom (unsigned int);
char *initstate (unsigned int, char *, size_t);
char *setstate (char *);
#endif

119 120
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
int putenv (char *);
R
Rich Felker 已提交
121 122 123 124
int posix_openpt (int);
int grantpt (int);
int unlockpt (int);
char *ptsname (int);
125 126 127 128 129 130 131 132 133 134 135 136 137
char *l64a (long);
long a64l (const char *);
void setkey (const char *);
double drand48 (void);
double erand48 (unsigned short [3]);
long int lrand48 (void);
long int nrand48 (unsigned short [3]);
long mrand48 (void);
long jrand48 (unsigned short [3]);
void srand48 (long);
unsigned short *seed48 (unsigned short [3]);
void lcong48 (unsigned short [7]);
#endif
R
Rich Felker 已提交
138

139
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
R
Rich Felker 已提交
140
#include <alloca.h>
141 142 143
char *mktemp (char *);
void *valloc (size_t);
void *memalign(size_t, size_t);
144 145
#define WCOREDUMP(s) ((s) & 0x80)
#define WIFCONTINUED(s) ((s) == 0xffff)
146 147 148
#endif

#ifdef _GNU_SOURCE
149
int clearenv(void);
150
int ptsname_r(int, char *, size_t);
151 152 153
char *ecvt(double, int, int *, int *);
char *fcvt(double, int, int *, int *);
char *gcvt(double, int, char *);
154
#endif
R
Rich Felker 已提交
155

156
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
157 158
#define mkstemp64 mkstemp
#endif
R
Rich Felker 已提交
159 160 161 162 163 164

#ifdef __cplusplus
}
#endif

#endif