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