1 | /* Copyright (C) 1991-2007, 2009-2011, 2012 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. |
3 | |
4 | The GNU C Library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Lesser General Public |
6 | License as published by the Free Software Foundation; either |
7 | version 2.1 of the License, or (at your option) any later version. |
8 | |
9 | The GNU C Library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Lesser General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Lesser General Public |
15 | License along with the GNU C Library; if not, see |
16 | <http://www.gnu.org/licenses/>. */ |
17 | |
18 | /* |
19 | * ISO C99 Standard: 7.20 General utilities <stdlib.h> |
20 | */ |
21 | |
22 | #ifndef _STDLIB_H |
23 | |
24 | #include <features.h> |
25 | |
26 | /* Get size_t, wchar_t and NULL from <stddef.h>. */ |
27 | #define __need_size_t |
28 | #ifndef __need_malloc_and_calloc |
29 | # define __need_wchar_t |
30 | # define __need_NULL |
31 | #endif |
32 | #include <stddef.h> |
33 | |
34 | __BEGIN_DECLS |
35 | |
36 | #ifndef __need_malloc_and_calloc |
37 | #define _STDLIB_H 1 |
38 | |
39 | #if (defined __USE_XOPEN || defined __USE_XOPEN2K8) && !defined _SYS_WAIT_H |
40 | /* XPG requires a few symbols from <sys/wait.h> being defined. */ |
41 | # include <bits/waitflags.h> |
42 | # include <bits/waitstatus.h> |
43 | |
44 | # ifdef __USE_BSD |
45 | |
46 | /* Lots of hair to allow traditional BSD use of `union wait' |
47 | as well as POSIX.1 use of `int' for the status word. */ |
48 | |
49 | # if defined __GNUC__ && !defined __cplusplus |
50 | # define __WAIT_INT(status) \ |
51 | (__extension__ (((union { __typeof(status) __in; int __i; }) \ |
52 | { .__in = (status) }).__i)) |
53 | # else |
54 | # define __WAIT_INT(status) (*(int *) &(status)) |
55 | # endif |
56 | |
57 | /* This is the type of the argument to `wait'. The funky union |
58 | causes redeclarations with either `int *' or `union wait *' to be |
59 | allowed without complaint. __WAIT_STATUS_DEFN is the type used in |
60 | the actual function definitions. */ |
61 | |
62 | # if !defined __GNUC__ || __GNUC__ < 2 || defined __cplusplus |
63 | # define __WAIT_STATUS void * |
64 | # define __WAIT_STATUS_DEFN void * |
65 | # else |
66 | /* This works in GCC 2.6.1 and later. */ |
67 | typedef union |
68 | { |
69 | union wait *__uptr; |
70 | int *__iptr; |
71 | } __WAIT_STATUS __attribute__ ((__transparent_union__)); |
72 | # define __WAIT_STATUS_DEFN int * |
73 | # endif |
74 | |
75 | # else /* Don't use BSD. */ |
76 | |
77 | # define __WAIT_INT(status) (status) |
78 | # define __WAIT_STATUS int * |
79 | # define __WAIT_STATUS_DEFN int * |
80 | |
81 | # endif /* Use BSD. */ |
82 | |
83 | /* Define the macros <sys/wait.h> also would define this way. */ |
84 | # define WEXITSTATUS(status) __WEXITSTATUS (__WAIT_INT (status)) |
85 | # define WTERMSIG(status) __WTERMSIG (__WAIT_INT (status)) |
86 | # define WSTOPSIG(status) __WSTOPSIG (__WAIT_INT (status)) |
87 | # define WIFEXITED(status) __WIFEXITED (__WAIT_INT (status)) |
88 | # define WIFSIGNALED(status) __WIFSIGNALED (__WAIT_INT (status)) |
89 | # define WIFSTOPPED(status) __WIFSTOPPED (__WAIT_INT (status)) |
90 | # ifdef __WIFCONTINUED |
91 | # define WIFCONTINUED(status) __WIFCONTINUED (__WAIT_INT (status)) |
92 | # endif |
93 | #endif /* X/Open or XPG7 and <sys/wait.h> not included. */ |
94 | |
95 | __BEGIN_NAMESPACE_STD |
96 | /* Returned by `div'. */ |
97 | typedef struct |
98 | { |
99 | int quot; /* Quotient. */ |
100 | int rem; /* Remainder. */ |
101 | } div_t; |
102 | |
103 | /* Returned by `ldiv'. */ |
104 | #ifndef __ldiv_t_defined |
105 | typedef struct |
106 | { |
107 | long int quot; /* Quotient. */ |
108 | long int rem; /* Remainder. */ |
109 | } ldiv_t; |
110 | # define __ldiv_t_defined 1 |
111 | #endif |
112 | __END_NAMESPACE_STD |
113 | |
114 | #if defined __USE_ISOC99 && !defined __lldiv_t_defined |
115 | __BEGIN_NAMESPACE_C99 |
116 | /* Returned by `lldiv'. */ |
117 | __extension__ typedef struct |
118 | { |
119 | long long int quot; /* Quotient. */ |
120 | long long int rem; /* Remainder. */ |
121 | } lldiv_t; |
122 | # define __lldiv_t_defined 1 |
123 | __END_NAMESPACE_C99 |
124 | #endif |
125 | |
126 | |
127 | /* The largest number rand will return (same as INT_MAX). */ |
128 | #define RAND_MAX 2147483647 |
129 | |
130 | |
131 | /* We define these the same for all machines. |
132 | Changes from this to the outside world should be done in `_exit'. */ |
133 | #define EXIT_FAILURE 1 /* Failing exit status. */ |
134 | #define EXIT_SUCCESS 0 /* Successful exit status. */ |
135 | |
136 | |
137 | /* Maximum length of a multibyte character in the current locale. */ |
138 | #define MB_CUR_MAX (__ctype_get_mb_cur_max ()) |
139 | extern size_t __ctype_get_mb_cur_max (void) __THROW __wur; |
140 | |
141 | |
142 | __BEGIN_NAMESPACE_STD |
143 | /* Convert a string to a floating-point number. */ |
144 | extern double atof (const char *__nptr) |
145 | __THROW __attribute_pure__ __nonnull ((1)) __wur; |
146 | /* Convert a string to an integer. */ |
147 | extern int atoi (const char *__nptr) |
148 | __THROW __attribute_pure__ __nonnull ((1)) __wur; |
149 | /* Convert a string to a long integer. */ |
150 | extern long int atol (const char *__nptr) |
151 | __THROW __attribute_pure__ __nonnull ((1)) __wur; |
152 | __END_NAMESPACE_STD |
153 | |
154 | #if defined __USE_ISOC99 || (defined __GLIBC_HAVE_LONG_LONG && defined __USE_MISC) |
155 | __BEGIN_NAMESPACE_C99 |
156 | /* Convert a string to a long long integer. */ |
157 | __extension__ extern long long int atoll (const char *__nptr) |
158 | __THROW __attribute_pure__ __nonnull ((1)) __wur; |
159 | __END_NAMESPACE_C99 |
160 | #endif |
161 | |
162 | __BEGIN_NAMESPACE_STD |
163 | /* Convert a string to a floating-point number. */ |
164 | extern double strtod (const char *__restrict __nptr, |
165 | char **__restrict __endptr) |
166 | __THROW __nonnull ((1)); |
167 | __END_NAMESPACE_STD |
168 | |
169 | #ifdef __USE_ISOC99 |
170 | __BEGIN_NAMESPACE_C99 |
171 | /* Likewise for `float' and `long double' sizes of floating-point numbers. */ |
172 | extern float strtof (const char *__restrict __nptr, |
173 | char **__restrict __endptr) __THROW __nonnull ((1)); |
174 | |
175 | extern long double strtold (const char *__restrict __nptr, |
176 | char **__restrict __endptr) |
177 | __THROW __nonnull ((1)); |
178 | __END_NAMESPACE_C99 |
179 | #endif |
180 | |
181 | __BEGIN_NAMESPACE_STD |
182 | /* Convert a string to a long integer. */ |
183 | extern long int strtol (const char *__restrict __nptr, |
184 | char **__restrict __endptr, int __base) |
185 | __THROW __nonnull ((1)); |
186 | /* Convert a string to an unsigned long integer. */ |
187 | extern unsigned long int strtoul (const char *__restrict __nptr, |
188 | char **__restrict __endptr, int __base) |
189 | __THROW __nonnull ((1)); |
190 | __END_NAMESPACE_STD |
191 | |
192 | #if defined __GLIBC_HAVE_LONG_LONG && defined __USE_BSD |
193 | /* Convert a string to a quadword integer. */ |
194 | __extension__ |
195 | extern long long int strtoq (const char *__restrict __nptr, |
196 | char **__restrict __endptr, int __base) |
197 | __THROW __nonnull ((1)); |
198 | /* Convert a string to an unsigned quadword integer. */ |
199 | __extension__ |
200 | extern unsigned long long int strtouq (const char *__restrict __nptr, |
201 | char **__restrict __endptr, int __base) |
202 | __THROW __nonnull ((1)); |
203 | #endif /* GCC and use BSD. */ |
204 | |
205 | #if defined __USE_ISOC99 || (defined __GLIBC_HAVE_LONG_LONG && defined __USE_MISC) |
206 | __BEGIN_NAMESPACE_C99 |
207 | /* Convert a string to a quadword integer. */ |
208 | __extension__ |
209 | extern long long int strtoll (const char *__restrict __nptr, |
210 | char **__restrict __endptr, int __base) |
211 | __THROW __nonnull ((1)); |
212 | /* Convert a string to an unsigned quadword integer. */ |
213 | __extension__ |
214 | extern unsigned long long int strtoull (const char *__restrict __nptr, |
215 | char **__restrict __endptr, int __base) |
216 | __THROW __nonnull ((1)); |
217 | __END_NAMESPACE_C99 |
218 | #endif /* ISO C99 or GCC and use MISC. */ |
219 | |
220 | |
221 | #ifdef __USE_GNU |
222 | /* The concept of one static locale per category is not very well |
223 | thought out. Many applications will need to process its data using |
224 | information from several different locales. Another problem is |
225 | the implementation of the internationalization handling in the |
226 | ISO C++ standard library. To support this another set of |
227 | the functions using locale data exist which take an additional |
228 | argument. |
229 | |
230 | Attention: even though several *_l interfaces are part of POSIX:2008, |
231 | these are not. */ |
232 | |
233 | /* Structure for reentrant locale using functions. This is an |
234 | (almost) opaque type for the user level programs. */ |
235 | # include <xlocale.h> |
236 | |
237 | /* Special versions of the functions above which take the locale to |
238 | use as an additional parameter. */ |
239 | extern long int strtol_l (const char *__restrict __nptr, |
240 | char **__restrict __endptr, int __base, |
241 | __locale_t __loc) __THROW __nonnull ((1, 4)); |
242 | |
243 | extern unsigned long int strtoul_l (const char *__restrict __nptr, |
244 | char **__restrict __endptr, |
245 | int __base, __locale_t __loc) |
246 | __THROW __nonnull ((1, 4)); |
247 | |
248 | __extension__ |
249 | extern long long int strtoll_l (const char *__restrict __nptr, |
250 | char **__restrict __endptr, int __base, |
251 | __locale_t __loc) |
252 | __THROW __nonnull ((1, 4)); |
253 | |
254 | __extension__ |
255 | extern unsigned long long int strtoull_l (const char *__restrict __nptr, |
256 | char **__restrict __endptr, |
257 | int __base, __locale_t __loc) |
258 | __THROW __nonnull ((1, 4)); |
259 | |
260 | extern double strtod_l (const char *__restrict __nptr, |
261 | char **__restrict __endptr, __locale_t __loc) |
262 | __THROW __nonnull ((1, 3)); |
263 | |
264 | extern float strtof_l (const char *__restrict __nptr, |
265 | char **__restrict __endptr, __locale_t __loc) |
266 | __THROW __nonnull ((1, 3)); |
267 | |
268 | extern long double strtold_l (const char *__restrict __nptr, |
269 | char **__restrict __endptr, |
270 | __locale_t __loc) |
271 | __THROW __nonnull ((1, 3)); |
272 | #endif /* GNU */ |
273 | |
274 | |
275 | #ifdef __USE_EXTERN_INLINES |
276 | __BEGIN_NAMESPACE_STD |
277 | __extern_inline double |
278 | __NTH (atof (const char *__nptr)) |
279 | { |
280 | return strtod (__nptr, (char **) NULL); |
281 | } |
282 | __extern_inline int |
283 | __NTH (atoi (const char *__nptr)) |
284 | { |
285 | return (int) strtol (__nptr, (char **) NULL, 10); |
286 | } |
287 | __extern_inline long int |
288 | __NTH (atol (const char *__nptr)) |
289 | { |
290 | return strtol (__nptr, (char **) NULL, 10); |
291 | } |
292 | __END_NAMESPACE_STD |
293 | |
294 | # if defined __USE_MISC || defined __USE_ISOC99 |
295 | __BEGIN_NAMESPACE_C99 |
296 | __extension__ __extern_inline long long int |
297 | __NTH (atoll (const char *__nptr)) |
298 | { |
299 | return strtoll (__nptr, (char **) NULL, 10); |
300 | } |
301 | __END_NAMESPACE_C99 |
302 | # endif |
303 | #endif /* Optimizing and Inlining. */ |
304 | |
305 | |
306 | #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED |
307 | /* Convert N to base 64 using the digits "./0-9A-Za-z", least-significant |
308 | digit first. Returns a pointer to static storage overwritten by the |
309 | next call. */ |
310 | extern char *l64a (long int __n) __THROW __wur; |
311 | |
312 | /* Read a number from a string S in base 64 as above. */ |
313 | extern long int a64l (const char *__s) |
314 | __THROW __attribute_pure__ __nonnull ((1)) __wur; |
315 | |
316 | #endif /* Use SVID || extended X/Open. */ |
317 | |
318 | #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED || defined __USE_BSD |
319 | # include <sys/types.h> /* we need int32_t... */ |
320 | |
321 | /* These are the functions that actually do things. The `random', `srandom', |
322 | `initstate' and `setstate' functions are those from BSD Unices. |
323 | The `rand' and `srand' functions are required by the ANSI standard. |
324 | We provide both interfaces to the same random number generator. */ |
325 | /* Return a random long integer between 0 and RAND_MAX inclusive. */ |
326 | extern long int random (void) __THROW; |
327 | |
328 | /* Seed the random number generator with the given number. */ |
329 | extern void srandom (unsigned int __seed) __THROW; |
330 | |
331 | /* Initialize the random number generator to use state buffer STATEBUF, |
332 | of length STATELEN, and seed it with SEED. Optimal lengths are 8, 16, |
333 | 32, 64, 128 and 256, the bigger the better; values less than 8 will |
334 | cause an error and values greater than 256 will be rounded down. */ |
335 | extern char *initstate (unsigned int __seed, char *__statebuf, |
336 | size_t __statelen) __THROW __nonnull ((2)); |
337 | |
338 | /* Switch the random number generator to state buffer STATEBUF, |
339 | which should have been previously initialized by `initstate'. */ |
340 | extern char *setstate (char *__statebuf) __THROW __nonnull ((1)); |
341 | |
342 | |
343 | # ifdef __USE_MISC |
344 | /* Reentrant versions of the `random' family of functions. |
345 | These functions all use the following data structure to contain |
346 | state, rather than global state variables. */ |
347 | |
348 | struct random_data |
349 | { |
350 | int32_t *fptr; /* Front pointer. */ |
351 | int32_t *rptr; /* Rear pointer. */ |
352 | int32_t *state; /* Array of state values. */ |
353 | int rand_type; /* Type of random number generator. */ |
354 | int rand_deg; /* Degree of random number generator. */ |
355 | int rand_sep; /* Distance between front and rear. */ |
356 | int32_t *end_ptr; /* Pointer behind state table. */ |
357 | }; |
358 | |
359 | extern int random_r (struct random_data *__restrict __buf, |
360 | int32_t *__restrict __result) __THROW __nonnull ((1, 2)); |
361 | |
362 | extern int srandom_r (unsigned int __seed, struct random_data *__buf) |
363 | __THROW __nonnull ((2)); |
364 | |
365 | extern int initstate_r (unsigned int __seed, char *__restrict __statebuf, |
366 | size_t __statelen, |
367 | struct random_data *__restrict __buf) |
368 | __THROW __nonnull ((2, 4)); |
369 | |
370 | extern int setstate_r (char *__restrict __statebuf, |
371 | struct random_data *__restrict __buf) |
372 | __THROW __nonnull ((1, 2)); |
373 | # endif /* Use misc. */ |
374 | #endif /* Use SVID || extended X/Open || BSD. */ |
375 | |
376 | |
377 | __BEGIN_NAMESPACE_STD |
378 | /* Return a random integer between 0 and RAND_MAX inclusive. */ |
379 | extern int rand (void) __THROW; |
380 | /* Seed the random number generator with the given number. */ |
381 | extern void srand (unsigned int __seed) __THROW; |
382 | __END_NAMESPACE_STD |
383 | |
384 | #ifdef __USE_POSIX |
385 | /* Reentrant interface according to POSIX.1. */ |
386 | extern int rand_r (unsigned int *__seed) __THROW; |
387 | #endif |
388 | |
389 | |
390 | #if defined __USE_SVID || defined __USE_XOPEN |
391 | /* System V style 48-bit random number generator functions. */ |
392 | |
393 | /* Return non-negative, double-precision floating-point value in [0.0,1.0). */ |
394 | extern double drand48 (void) __THROW; |
395 | extern double erand48 (unsigned short int __xsubi[3]) __THROW __nonnull ((1)); |
396 | |
397 | /* Return non-negative, long integer in [0,2^31). */ |
398 | extern long int lrand48 (void) __THROW; |
399 | extern long int nrand48 (unsigned short int __xsubi[3]) |
400 | __THROW __nonnull ((1)); |
401 | |
402 | /* Return signed, long integers in [-2^31,2^31). */ |
403 | extern long int mrand48 (void) __THROW; |
404 | extern long int jrand48 (unsigned short int __xsubi[3]) |
405 | __THROW __nonnull ((1)); |
406 | |
407 | /* Seed random number generator. */ |
408 | extern void srand48 (long int __seedval) __THROW; |
409 | extern unsigned short int *seed48 (unsigned short int __seed16v[3]) |
410 | __THROW __nonnull ((1)); |
411 | extern void lcong48 (unsigned short int __param[7]) __THROW __nonnull ((1)); |
412 | |
413 | # ifdef __USE_MISC |
414 | /* Data structure for communication with thread safe versions. This |
415 | type is to be regarded as opaque. It's only exported because users |
416 | have to allocate objects of this type. */ |
417 | struct drand48_data |
418 | { |
419 | unsigned short int __x[3]; /* Current state. */ |
420 | unsigned short int __old_x[3]; /* Old state. */ |
421 | unsigned short int __c; /* Additive const. in congruential formula. */ |
422 | unsigned short int __init; /* Flag for initializing. */ |
423 | unsigned long long int __a; /* Factor in congruential formula. */ |
424 | }; |
425 | |
426 | /* Return non-negative, double-precision floating-point value in [0.0,1.0). */ |
427 | extern int drand48_r (struct drand48_data *__restrict __buffer, |
428 | double *__restrict __result) __THROW __nonnull ((1, 2)); |
429 | extern int erand48_r (unsigned short int __xsubi[3], |
430 | struct drand48_data *__restrict __buffer, |
431 | double *__restrict __result) __THROW __nonnull ((1, 2)); |
432 | |
433 | /* Return non-negative, long integer in [0,2^31). */ |
434 | extern int lrand48_r (struct drand48_data *__restrict __buffer, |
435 | long int *__restrict __result) |
436 | __THROW __nonnull ((1, 2)); |
437 | extern int nrand48_r (unsigned short int __xsubi[3], |
438 | struct drand48_data *__restrict __buffer, |
439 | long int *__restrict __result) |
440 | __THROW __nonnull ((1, 2)); |
441 | |
442 | /* Return signed, long integers in [-2^31,2^31). */ |
443 | extern int mrand48_r (struct drand48_data *__restrict __buffer, |
444 | long int *__restrict __result) |
445 | __THROW __nonnull ((1, 2)); |
446 | extern int jrand48_r (unsigned short int __xsubi[3], |
447 | struct drand48_data *__restrict __buffer, |
448 | long int *__restrict __result) |
449 | __THROW __nonnull ((1, 2)); |
450 | |
451 | /* Seed random number generator. */ |
452 | extern int srand48_r (long int __seedval, struct drand48_data *__buffer) |
453 | __THROW __nonnull ((2)); |
454 | |
455 | extern int seed48_r (unsigned short int __seed16v[3], |
456 | struct drand48_data *__buffer) __THROW __nonnull ((1, 2)); |
457 | |
458 | extern int lcong48_r (unsigned short int __param[7], |
459 | struct drand48_data *__buffer) |
460 | __THROW __nonnull ((1, 2)); |
461 | # endif /* Use misc. */ |
462 | #endif /* Use SVID or X/Open. */ |
463 | |
464 | #endif /* don't just need malloc and calloc */ |
465 | |
466 | #ifndef __malloc_and_calloc_defined |
467 | # define __malloc_and_calloc_defined |
468 | __BEGIN_NAMESPACE_STD |
469 | /* Allocate SIZE bytes of memory. */ |
470 | extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur; |
471 | /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */ |
472 | extern void *calloc (size_t __nmemb, size_t __size) |
473 | __THROW __attribute_malloc__ __wur; |
474 | __END_NAMESPACE_STD |
475 | #endif |
476 | |
477 | #ifndef __need_malloc_and_calloc |
478 | __BEGIN_NAMESPACE_STD |
479 | /* Re-allocate the previously allocated block |
480 | in PTR, making the new block SIZE bytes long. */ |
481 | /* __attribute_malloc__ is not used, because if realloc returns |
482 | the same pointer that was passed to it, aliasing needs to be allowed |
483 | between objects pointed by the old and new pointers. */ |
484 | extern void *realloc (void *__ptr, size_t __size) |
485 | __THROW __attribute_warn_unused_result__; |
486 | /* Free a block allocated by `malloc', `realloc' or `calloc'. */ |
487 | extern void free (void *__ptr) __THROW; |
488 | __END_NAMESPACE_STD |
489 | |
490 | #ifdef __USE_MISC |
491 | /* Free a block. An alias for `free'. (Sun Unices). */ |
492 | extern void cfree (void *__ptr) __THROW; |
493 | #endif /* Use misc. */ |
494 | |
495 | #if defined __USE_GNU || defined __USE_BSD || defined __USE_MISC |
496 | # include <alloca.h> |
497 | #endif /* Use GNU, BSD, or misc. */ |
498 | |
499 | #if (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K) \ |
500 | || defined __USE_BSD |
501 | /* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */ |
502 | extern void *valloc (size_t __size) __THROW __attribute_malloc__ __wur; |
503 | #endif |
504 | |
505 | #ifdef __USE_XOPEN2K |
506 | /* Allocate memory of SIZE bytes with an alignment of ALIGNMENT. */ |
507 | extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size) |
508 | __THROW __nonnull ((1)) __wur; |
509 | #endif |
510 | |
511 | #ifdef __USE_ISOC11 |
512 | /* ISO C variant of aligned allocation. */ |
513 | extern void *aligned_alloc (size_t __alignment, size_t __size) |
514 | __THROW __wur __attribute__ ((__malloc__, __alloc_size__ (2))); |
515 | #endif |
516 | |
517 | __BEGIN_NAMESPACE_STD |
518 | /* Abort execution and generate a core-dump. */ |
519 | extern void abort (void) __THROW __attribute__ ((__noreturn__)); |
520 | |
521 | |
522 | /* Register a function to be called when `exit' is called. */ |
523 | extern int atexit (void (*__func) (void)) __THROW __nonnull ((1)); |
524 | |
525 | #if defined __USE_ISOC11 || defined __USE_ISOCXX11 |
526 | /* Register a function to be called when `quick_exit' is called. */ |
527 | # ifdef __cplusplus |
528 | extern "C++" int at_quick_exit (void (*__func) (void)) |
529 | __THROW __asm ("at_quick_exit" ) __nonnull ((1)); |
530 | # else |
531 | extern int at_quick_exit (void (*__func) (void)) __THROW __nonnull ((1)); |
532 | # endif |
533 | #endif |
534 | __END_NAMESPACE_STD |
535 | |
536 | #ifdef __USE_MISC |
537 | /* Register a function to be called with the status |
538 | given to `exit' and the given argument. */ |
539 | extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg) |
540 | __THROW __nonnull ((1)); |
541 | #endif |
542 | |
543 | __BEGIN_NAMESPACE_STD |
544 | /* Call all functions registered with `atexit' and `on_exit', |
545 | in the reverse of the order in which they were registered, |
546 | perform stdio cleanup, and terminate program execution with STATUS. */ |
547 | extern void exit (int __status) __THROW __attribute__ ((__noreturn__)); |
548 | |
549 | #if defined __USE_ISOC11 || defined __USE_ISOCXX11 |
550 | /* Call all functions registered with `at_quick_exit' in the reverse |
551 | of the order in which they were registered and terminate program |
552 | execution with STATUS. */ |
553 | extern void quick_exit (int __status) __THROW __attribute__ ((__noreturn__)); |
554 | #endif |
555 | __END_NAMESPACE_STD |
556 | |
557 | #ifdef __USE_ISOC99 |
558 | __BEGIN_NAMESPACE_C99 |
559 | /* Terminate the program with STATUS without calling any of the |
560 | functions registered with `atexit' or `on_exit'. */ |
561 | extern void _Exit (int __status) __THROW __attribute__ ((__noreturn__)); |
562 | __END_NAMESPACE_C99 |
563 | #endif |
564 | |
565 | |
566 | __BEGIN_NAMESPACE_STD |
567 | /* Return the value of envariable NAME, or NULL if it doesn't exist. */ |
568 | extern char *getenv (const char *__name) __THROW __nonnull ((1)) __wur; |
569 | __END_NAMESPACE_STD |
570 | |
571 | /* This function is similar to the above but returns NULL if the |
572 | programs is running with SUID or SGID enabled. */ |
573 | extern char *__secure_getenv (const char *__name) |
574 | __THROW __nonnull ((1)) __wur; |
575 | |
576 | #if defined __USE_SVID || defined __USE_XOPEN |
577 | /* The SVID says this is in <stdio.h>, but this seems a better place. */ |
578 | /* Put STRING, which is of the form "NAME=VALUE", in the environment. |
579 | If there is no `=', remove NAME from the environment. */ |
580 | extern int putenv (char *__string) __THROW __nonnull ((1)); |
581 | #endif |
582 | |
583 | #if defined __USE_BSD || defined __USE_XOPEN2K |
584 | /* Set NAME to VALUE in the environment. |
585 | If REPLACE is nonzero, overwrite an existing value. */ |
586 | extern int setenv (const char *__name, const char *__value, int __replace) |
587 | __THROW __nonnull ((2)); |
588 | |
589 | /* Remove the variable NAME from the environment. */ |
590 | extern int unsetenv (const char *__name) __THROW __nonnull ((1)); |
591 | #endif |
592 | |
593 | #ifdef __USE_MISC |
594 | /* The `clearenv' was planned to be added to POSIX.1 but probably |
595 | never made it. Nevertheless the POSIX.9 standard (POSIX bindings |
596 | for Fortran 77) requires this function. */ |
597 | extern int clearenv (void) __THROW; |
598 | #endif |
599 | |
600 | |
601 | #if defined __USE_MISC \ |
602 | || (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K) |
603 | /* Generate a unique temporary file name from TEMPLATE. |
604 | The last six characters of TEMPLATE must be "XXXXXX"; |
605 | they are replaced with a string that makes the file name unique. |
606 | Always returns TEMPLATE, it's either a temporary file name or a null |
607 | string if it cannot get a unique file name. */ |
608 | extern char *mktemp (char *__template) __THROW __nonnull ((1)); |
609 | #endif |
610 | |
611 | #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED \ |
612 | || defined __USE_XOPEN2K8 |
613 | /* Generate a unique temporary file name from TEMPLATE. |
614 | The last six characters of TEMPLATE must be "XXXXXX"; |
615 | they are replaced with a string that makes the filename unique. |
616 | Returns a file descriptor open on the file for reading and writing, |
617 | or -1 if it cannot create a uniquely-named file. |
618 | |
619 | This function is a possible cancellation point and therefore not |
620 | marked with __THROW. */ |
621 | # ifndef __USE_FILE_OFFSET64 |
622 | extern int mkstemp (char *__template) __nonnull ((1)) __wur; |
623 | # else |
624 | # ifdef __REDIRECT |
625 | extern int __REDIRECT (mkstemp, (char *__template), mkstemp64) |
626 | __nonnull ((1)) __wur; |
627 | # else |
628 | # define mkstemp mkstemp64 |
629 | # endif |
630 | # endif |
631 | # ifdef __USE_LARGEFILE64 |
632 | extern int mkstemp64 (char *__template) __nonnull ((1)) __wur; |
633 | # endif |
634 | #endif |
635 | |
636 | #ifdef __USE_MISC |
637 | /* Similar to mkstemp, but the template can have a suffix after the |
638 | XXXXXX. The length of the suffix is specified in the second |
639 | parameter. |
640 | |
641 | This function is a possible cancellation point and therefore not |
642 | marked with __THROW. */ |
643 | # ifndef __USE_FILE_OFFSET64 |
644 | extern int mkstemps (char *__template, int __suffixlen) __nonnull ((1)) __wur; |
645 | # else |
646 | # ifdef __REDIRECT |
647 | extern int __REDIRECT (mkstemps, (char *__template, int __suffixlen), |
648 | mkstemps64) __nonnull ((1)) __wur; |
649 | # else |
650 | # define mkstemps mkstemps64 |
651 | # endif |
652 | # endif |
653 | # ifdef __USE_LARGEFILE64 |
654 | extern int mkstemps64 (char *__template, int __suffixlen) |
655 | __nonnull ((1)) __wur; |
656 | # endif |
657 | #endif |
658 | |
659 | #if defined __USE_BSD || defined __USE_XOPEN2K8 |
660 | /* Create a unique temporary directory from TEMPLATE. |
661 | The last six characters of TEMPLATE must be "XXXXXX"; |
662 | they are replaced with a string that makes the directory name unique. |
663 | Returns TEMPLATE, or a null pointer if it cannot get a unique name. |
664 | The directory is created mode 700. */ |
665 | extern char *mkdtemp (char *__template) __THROW __nonnull ((1)) __wur; |
666 | #endif |
667 | |
668 | #ifdef __USE_GNU |
669 | /* Generate a unique temporary file name from TEMPLATE similar to |
670 | mkstemp. But allow the caller to pass additional flags which are |
671 | used in the open call to create the file.. |
672 | |
673 | This function is a possible cancellation point and therefore not |
674 | marked with __THROW. */ |
675 | # ifndef __USE_FILE_OFFSET64 |
676 | extern int mkostemp (char *__template, int __flags) __nonnull ((1)) __wur; |
677 | # else |
678 | # ifdef __REDIRECT |
679 | extern int __REDIRECT (mkostemp, (char *__template, int __flags), mkostemp64) |
680 | __nonnull ((1)) __wur; |
681 | # else |
682 | # define mkostemp mkostemp64 |
683 | # endif |
684 | # endif |
685 | # ifdef __USE_LARGEFILE64 |
686 | extern int mkostemp64 (char *__template, int __flags) __nonnull ((1)) __wur; |
687 | # endif |
688 | |
689 | /* Similar to mkostemp, but the template can have a suffix after the |
690 | XXXXXX. The length of the suffix is specified in the second |
691 | parameter. |
692 | |
693 | This function is a possible cancellation point and therefore not |
694 | marked with __THROW. */ |
695 | # ifndef __USE_FILE_OFFSET64 |
696 | extern int mkostemps (char *__template, int __suffixlen, int __flags) |
697 | __nonnull ((1)) __wur; |
698 | # else |
699 | # ifdef __REDIRECT |
700 | extern int __REDIRECT (mkostemps, (char *__template, int __suffixlen, |
701 | int __flags), mkostemps64) |
702 | __nonnull ((1)) __wur; |
703 | # else |
704 | # define mkostemps mkostemps64 |
705 | # endif |
706 | # endif |
707 | # ifdef __USE_LARGEFILE64 |
708 | extern int mkostemps64 (char *__template, int __suffixlen, int __flags) |
709 | __nonnull ((1)) __wur; |
710 | # endif |
711 | #endif |
712 | |
713 | |
714 | __BEGIN_NAMESPACE_STD |
715 | /* Execute the given line as a shell command. |
716 | |
717 | This function is a cancellation point and therefore not marked with |
718 | __THROW. */ |
719 | extern int system (const char *__command) __wur; |
720 | __END_NAMESPACE_STD |
721 | |
722 | |
723 | #ifdef __USE_GNU |
724 | /* Return a malloc'd string containing the canonical absolute name of the |
725 | existing named file. */ |
726 | extern char *canonicalize_file_name (const char *__name) |
727 | __THROW __nonnull ((1)) __wur; |
728 | #endif |
729 | |
730 | #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED |
731 | /* Return the canonical absolute name of file NAME. If RESOLVED is |
732 | null, the result is malloc'd; otherwise, if the canonical name is |
733 | PATH_MAX chars or more, returns null with `errno' set to |
734 | ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, |
735 | returns the name in RESOLVED. */ |
736 | extern char *realpath (const char *__restrict __name, |
737 | char *__restrict __resolved) __THROW __wur; |
738 | #endif |
739 | |
740 | |
741 | /* Shorthand for type of comparison functions. */ |
742 | #ifndef __COMPAR_FN_T |
743 | # define __COMPAR_FN_T |
744 | typedef int (*__compar_fn_t) (const void *, const void *); |
745 | |
746 | # ifdef __USE_GNU |
747 | typedef __compar_fn_t comparison_fn_t; |
748 | # endif |
749 | #endif |
750 | #ifdef __USE_GNU |
751 | typedef int (*__compar_d_fn_t) (const void *, const void *, void *); |
752 | #endif |
753 | |
754 | __BEGIN_NAMESPACE_STD |
755 | /* Do a binary search for KEY in BASE, which consists of NMEMB elements |
756 | of SIZE bytes each, using COMPAR to perform the comparisons. */ |
757 | extern void *bsearch (const void *__key, const void *__base, |
758 | size_t __nmemb, size_t __size, __compar_fn_t __compar) |
759 | __nonnull ((1, 2, 5)) __wur; |
760 | |
761 | /* Sort NMEMB elements of BASE, of SIZE bytes each, |
762 | using COMPAR to perform the comparisons. */ |
763 | extern void qsort (void *__base, size_t __nmemb, size_t __size, |
764 | __compar_fn_t __compar) __nonnull ((1, 4)); |
765 | #ifdef __USE_GNU |
766 | extern void qsort_r (void *__base, size_t __nmemb, size_t __size, |
767 | __compar_d_fn_t __compar, void *__arg) |
768 | __nonnull ((1, 4)); |
769 | #endif |
770 | |
771 | |
772 | /* Return the absolute value of X. */ |
773 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur; |
774 | extern long int labs (long int __x) __THROW __attribute__ ((__const__)) __wur; |
775 | __END_NAMESPACE_STD |
776 | |
777 | #ifdef __USE_ISOC99 |
778 | __extension__ extern long long int llabs (long long int __x) |
779 | __THROW __attribute__ ((__const__)) __wur; |
780 | #endif |
781 | |
782 | |
783 | __BEGIN_NAMESPACE_STD |
784 | /* Return the `div_t', `ldiv_t' or `lldiv_t' representation |
785 | of the value of NUMER over DENOM. */ |
786 | /* GCC may have built-ins for these someday. */ |
787 | extern div_t div (int __numer, int __denom) |
788 | __THROW __attribute__ ((__const__)) __wur; |
789 | extern ldiv_t ldiv (long int __numer, long int __denom) |
790 | __THROW __attribute__ ((__const__)) __wur; |
791 | __END_NAMESPACE_STD |
792 | |
793 | #ifdef __USE_ISOC99 |
794 | __BEGIN_NAMESPACE_C99 |
795 | __extension__ extern lldiv_t lldiv (long long int __numer, |
796 | long long int __denom) |
797 | __THROW __attribute__ ((__const__)) __wur; |
798 | __END_NAMESPACE_C99 |
799 | #endif |
800 | |
801 | |
802 | #if (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K) \ |
803 | || defined __USE_SVID |
804 | /* Convert floating point numbers to strings. The returned values are |
805 | valid only until another call to the same function. */ |
806 | |
807 | /* Convert VALUE to a string with NDIGIT digits and return a pointer to |
808 | this. Set *DECPT with the position of the decimal character and *SIGN |
809 | with the sign of the number. */ |
810 | extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt, |
811 | int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur; |
812 | |
813 | /* Convert VALUE to a string rounded to NDIGIT decimal digits. Set *DECPT |
814 | with the position of the decimal character and *SIGN with the sign of |
815 | the number. */ |
816 | extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt, |
817 | int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur; |
818 | |
819 | /* If possible convert VALUE to a string with NDIGIT significant digits. |
820 | Otherwise use exponential representation. The resulting string will |
821 | be written to BUF. */ |
822 | extern char *gcvt (double __value, int __ndigit, char *__buf) |
823 | __THROW __nonnull ((3)) __wur; |
824 | |
825 | |
826 | # ifdef __USE_MISC |
827 | /* Long double versions of above functions. */ |
828 | extern char *qecvt (long double __value, int __ndigit, |
829 | int *__restrict __decpt, int *__restrict __sign) |
830 | __THROW __nonnull ((3, 4)) __wur; |
831 | extern char *qfcvt (long double __value, int __ndigit, |
832 | int *__restrict __decpt, int *__restrict __sign) |
833 | __THROW __nonnull ((3, 4)) __wur; |
834 | extern char *qgcvt (long double __value, int __ndigit, char *__buf) |
835 | __THROW __nonnull ((3)) __wur; |
836 | |
837 | |
838 | /* Reentrant version of the functions above which provide their own |
839 | buffers. */ |
840 | extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt, |
841 | int *__restrict __sign, char *__restrict __buf, |
842 | size_t __len) __THROW __nonnull ((3, 4, 5)); |
843 | extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt, |
844 | int *__restrict __sign, char *__restrict __buf, |
845 | size_t __len) __THROW __nonnull ((3, 4, 5)); |
846 | |
847 | extern int qecvt_r (long double __value, int __ndigit, |
848 | int *__restrict __decpt, int *__restrict __sign, |
849 | char *__restrict __buf, size_t __len) |
850 | __THROW __nonnull ((3, 4, 5)); |
851 | extern int qfcvt_r (long double __value, int __ndigit, |
852 | int *__restrict __decpt, int *__restrict __sign, |
853 | char *__restrict __buf, size_t __len) |
854 | __THROW __nonnull ((3, 4, 5)); |
855 | # endif /* misc */ |
856 | #endif /* use MISC || use X/Open Unix */ |
857 | |
858 | |
859 | __BEGIN_NAMESPACE_STD |
860 | /* Return the length of the multibyte character |
861 | in S, which is no longer than N. */ |
862 | extern int mblen (const char *__s, size_t __n) __THROW __wur; |
863 | /* Return the length of the given multibyte character, |
864 | putting its `wchar_t' representation in *PWC. */ |
865 | extern int mbtowc (wchar_t *__restrict __pwc, |
866 | const char *__restrict __s, size_t __n) __THROW __wur; |
867 | /* Put the multibyte character represented |
868 | by WCHAR in S, returning its length. */ |
869 | extern int wctomb (char *__s, wchar_t __wchar) __THROW __wur; |
870 | |
871 | |
872 | /* Convert a multibyte string to a wide char string. */ |
873 | extern size_t mbstowcs (wchar_t *__restrict __pwcs, |
874 | const char *__restrict __s, size_t __n) __THROW; |
875 | /* Convert a wide char string to multibyte string. */ |
876 | extern size_t wcstombs (char *__restrict __s, |
877 | const wchar_t *__restrict __pwcs, size_t __n) |
878 | __THROW; |
879 | __END_NAMESPACE_STD |
880 | |
881 | |
882 | #ifdef __USE_SVID |
883 | /* Determine whether the string value of RESPONSE matches the affirmation |
884 | or negative response expression as specified by the LC_MESSAGES category |
885 | in the program's current locale. Returns 1 if affirmative, 0 if |
886 | negative, and -1 if not matching. */ |
887 | extern int rpmatch (const char *__response) __THROW __nonnull ((1)) __wur; |
888 | #endif |
889 | |
890 | |
891 | #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8 |
892 | /* Parse comma separated suboption from *OPTIONP and match against |
893 | strings in TOKENS. If found return index and set *VALUEP to |
894 | optional value introduced by an equal sign. If the suboption is |
895 | not part of TOKENS return in *VALUEP beginning of unknown |
896 | suboption. On exit *OPTIONP is set to the beginning of the next |
897 | token or at the terminating NUL character. */ |
898 | extern int getsubopt (char **__restrict __optionp, |
899 | char *const *__restrict __tokens, |
900 | char **__restrict __valuep) |
901 | __THROW __nonnull ((1, 2, 3)) __wur; |
902 | #endif |
903 | |
904 | |
905 | #ifdef __USE_XOPEN |
906 | /* Setup DES tables according KEY. */ |
907 | extern void setkey (const char *__key) __THROW __nonnull ((1)); |
908 | #endif |
909 | |
910 | |
911 | /* X/Open pseudo terminal handling. */ |
912 | |
913 | #ifdef __USE_XOPEN2KXSI |
914 | /* Return a master pseudo-terminal handle. */ |
915 | extern int posix_openpt (int __oflag) __wur; |
916 | #endif |
917 | |
918 | #ifdef __USE_XOPEN |
919 | /* The next four functions all take a master pseudo-tty fd and |
920 | perform an operation on the associated slave: */ |
921 | |
922 | /* Chown the slave to the calling user. */ |
923 | extern int grantpt (int __fd) __THROW; |
924 | |
925 | /* Release an internal lock so the slave can be opened. |
926 | Call after grantpt(). */ |
927 | extern int unlockpt (int __fd) __THROW; |
928 | |
929 | /* Return the pathname of the pseudo terminal slave assoicated with |
930 | the master FD is open on, or NULL on errors. |
931 | The returned storage is good until the next call to this function. */ |
932 | extern char *ptsname (int __fd) __THROW __wur; |
933 | #endif |
934 | |
935 | #ifdef __USE_GNU |
936 | /* Store at most BUFLEN characters of the pathname of the slave pseudo |
937 | terminal associated with the master FD is open on in BUF. |
938 | Return 0 on success, otherwise an error number. */ |
939 | extern int ptsname_r (int __fd, char *__buf, size_t __buflen) |
940 | __THROW __nonnull ((2)); |
941 | |
942 | /* Open a master pseudo terminal and return its file descriptor. */ |
943 | extern int getpt (void); |
944 | #endif |
945 | |
946 | #ifdef __USE_BSD |
947 | /* Put the 1 minute, 5 minute and 15 minute load averages into the first |
948 | NELEM elements of LOADAVG. Return the number written (never more than |
949 | three, but may be less than NELEM), or -1 if an error occurred. */ |
950 | extern int getloadavg (double __loadavg[], int __nelem) |
951 | __THROW __nonnull ((1)); |
952 | #endif |
953 | |
954 | |
955 | /* Define some macros helping to catch buffer overflows. */ |
956 | #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function |
957 | # include <bits/stdlib.h> |
958 | #endif |
959 | #ifdef __LDBL_COMPAT |
960 | # include <bits/stdlib-ldbl.h> |
961 | #endif |
962 | |
963 | #endif /* don't just need malloc and calloc */ |
964 | #undef __need_malloc_and_calloc |
965 | |
966 | __END_DECLS |
967 | |
968 | #endif /* stdlib.h */ |
969 | |