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