Fix trailing blank.
[glibc.git] / stdlib / stdlib.h
blob6bf708a1676f7943e3eb7c2ace6de3d06054c143
1 /* Copyright (C) 1991-2013 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 #include <features.h>
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>
34 __BEGIN_DECLS
36 #ifndef __need_malloc_and_calloc
37 #define _STDLIB_H 1
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>
44 # ifdef __USE_BSD
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. */
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
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. */
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
69 union wait *__uptr;
70 int *__iptr;
71 } __WAIT_STATUS __attribute__ ((__transparent_union__));
72 # define __WAIT_STATUS_DEFN int *
73 # endif
75 # else /* Don't use BSD. */
77 # define __WAIT_INT(status) (status)
78 # define __WAIT_STATUS int *
79 # define __WAIT_STATUS_DEFN int *
81 # endif /* Use BSD. */
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. */
95 __BEGIN_NAMESPACE_STD
96 /* Returned by `div'. */
97 typedef struct
99 int quot; /* Quotient. */
100 int rem; /* Remainder. */
101 } div_t;
103 /* Returned by `ldiv'. */
104 #ifndef __ldiv_t_defined
105 typedef struct
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
114 #if defined __USE_ISOC99 && !defined __lldiv_t_defined
115 __BEGIN_NAMESPACE_C99
116 /* Returned by `lldiv'. */
117 __extension__ typedef struct
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
127 /* The largest number rand will return (same as INT_MAX). */
128 #define RAND_MAX 2147483647
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. */
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;
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
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
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
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));
175 extern long double strtold (const char *__restrict __nptr,
176 char **__restrict __endptr)
177 __THROW __nonnull ((1));
178 __END_NAMESPACE_C99
179 #endif
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
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. */
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. */
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.
230 Attention: even though several *_l interfaces are part of POSIX:2008,
231 these are not. */
233 /* Structure for reentrant locale using functions. This is an
234 (almost) opaque type for the user level programs. */
235 # include <xlocale.h>
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));
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));
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));
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));
260 extern double strtod_l (const char *__restrict __nptr,
261 char **__restrict __endptr, __locale_t __loc)
262 __THROW __nonnull ((1, 3));
264 extern float strtof_l (const char *__restrict __nptr,
265 char **__restrict __endptr, __locale_t __loc)
266 __THROW __nonnull ((1, 3));
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 */
275 #ifdef __USE_EXTERN_INLINES
276 __BEGIN_NAMESPACE_STD
277 __extern_inline int
278 __NTH (atoi (const char *__nptr))
280 return (int) strtol (__nptr, (char **) NULL, 10);
282 __extern_inline long int
283 __NTH (atol (const char *__nptr))
285 return strtol (__nptr, (char **) NULL, 10);
287 __END_NAMESPACE_STD
289 # if defined __USE_MISC || defined __USE_ISOC99
290 __BEGIN_NAMESPACE_C99
291 __extension__ __extern_inline long long int
292 __NTH (atoll (const char *__nptr))
294 return strtoll (__nptr, (char **) NULL, 10);
296 __END_NAMESPACE_C99
297 # endif
298 #endif /* Optimizing and Inlining. */
301 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED
302 /* Convert N to base 64 using the digits "./0-9A-Za-z", least-significant
303 digit first. Returns a pointer to static storage overwritten by the
304 next call. */
305 extern char *l64a (long int __n) __THROW __wur;
307 /* Read a number from a string S in base 64 as above. */
308 extern long int a64l (const char *__s)
309 __THROW __attribute_pure__ __nonnull ((1)) __wur;
311 #endif /* Use SVID || extended X/Open. */
313 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED || defined __USE_BSD
314 # include <sys/types.h> /* we need int32_t... */
316 /* These are the functions that actually do things. The `random', `srandom',
317 `initstate' and `setstate' functions are those from BSD Unices.
318 The `rand' and `srand' functions are required by the ANSI standard.
319 We provide both interfaces to the same random number generator. */
320 /* Return a random long integer between 0 and RAND_MAX inclusive. */
321 extern long int random (void) __THROW;
323 /* Seed the random number generator with the given number. */
324 extern void srandom (unsigned int __seed) __THROW;
326 /* Initialize the random number generator to use state buffer STATEBUF,
327 of length STATELEN, and seed it with SEED. Optimal lengths are 8, 16,
328 32, 64, 128 and 256, the bigger the better; values less than 8 will
329 cause an error and values greater than 256 will be rounded down. */
330 extern char *initstate (unsigned int __seed, char *__statebuf,
331 size_t __statelen) __THROW __nonnull ((2));
333 /* Switch the random number generator to state buffer STATEBUF,
334 which should have been previously initialized by `initstate'. */
335 extern char *setstate (char *__statebuf) __THROW __nonnull ((1));
338 # ifdef __USE_MISC
339 /* Reentrant versions of the `random' family of functions.
340 These functions all use the following data structure to contain
341 state, rather than global state variables. */
343 struct random_data
345 int32_t *fptr; /* Front pointer. */
346 int32_t *rptr; /* Rear pointer. */
347 int32_t *state; /* Array of state values. */
348 int rand_type; /* Type of random number generator. */
349 int rand_deg; /* Degree of random number generator. */
350 int rand_sep; /* Distance between front and rear. */
351 int32_t *end_ptr; /* Pointer behind state table. */
354 extern int random_r (struct random_data *__restrict __buf,
355 int32_t *__restrict __result) __THROW __nonnull ((1, 2));
357 extern int srandom_r (unsigned int __seed, struct random_data *__buf)
358 __THROW __nonnull ((2));
360 extern int initstate_r (unsigned int __seed, char *__restrict __statebuf,
361 size_t __statelen,
362 struct random_data *__restrict __buf)
363 __THROW __nonnull ((2, 4));
365 extern int setstate_r (char *__restrict __statebuf,
366 struct random_data *__restrict __buf)
367 __THROW __nonnull ((1, 2));
368 # endif /* Use misc. */
369 #endif /* Use SVID || extended X/Open || BSD. */
372 __BEGIN_NAMESPACE_STD
373 /* Return a random integer between 0 and RAND_MAX inclusive. */
374 extern int rand (void) __THROW;
375 /* Seed the random number generator with the given number. */
376 extern void srand (unsigned int __seed) __THROW;
377 __END_NAMESPACE_STD
379 #ifdef __USE_POSIX
380 /* Reentrant interface according to POSIX.1. */
381 extern int rand_r (unsigned int *__seed) __THROW;
382 #endif
385 #if defined __USE_SVID || defined __USE_XOPEN
386 /* System V style 48-bit random number generator functions. */
388 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
389 extern double drand48 (void) __THROW;
390 extern double erand48 (unsigned short int __xsubi[3]) __THROW __nonnull ((1));
392 /* Return non-negative, long integer in [0,2^31). */
393 extern long int lrand48 (void) __THROW;
394 extern long int nrand48 (unsigned short int __xsubi[3])
395 __THROW __nonnull ((1));
397 /* Return signed, long integers in [-2^31,2^31). */
398 extern long int mrand48 (void) __THROW;
399 extern long int jrand48 (unsigned short int __xsubi[3])
400 __THROW __nonnull ((1));
402 /* Seed random number generator. */
403 extern void srand48 (long int __seedval) __THROW;
404 extern unsigned short int *seed48 (unsigned short int __seed16v[3])
405 __THROW __nonnull ((1));
406 extern void lcong48 (unsigned short int __param[7]) __THROW __nonnull ((1));
408 # ifdef __USE_MISC
409 /* Data structure for communication with thread safe versions. This
410 type is to be regarded as opaque. It's only exported because users
411 have to allocate objects of this type. */
412 struct drand48_data
414 unsigned short int __x[3]; /* Current state. */
415 unsigned short int __old_x[3]; /* Old state. */
416 unsigned short int __c; /* Additive const. in congruential formula. */
417 unsigned short int __init; /* Flag for initializing. */
418 unsigned long long int __a; /* Factor in congruential formula. */
421 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
422 extern int drand48_r (struct drand48_data *__restrict __buffer,
423 double *__restrict __result) __THROW __nonnull ((1, 2));
424 extern int erand48_r (unsigned short int __xsubi[3],
425 struct drand48_data *__restrict __buffer,
426 double *__restrict __result) __THROW __nonnull ((1, 2));
428 /* Return non-negative, long integer in [0,2^31). */
429 extern int lrand48_r (struct drand48_data *__restrict __buffer,
430 long int *__restrict __result)
431 __THROW __nonnull ((1, 2));
432 extern int nrand48_r (unsigned short int __xsubi[3],
433 struct drand48_data *__restrict __buffer,
434 long int *__restrict __result)
435 __THROW __nonnull ((1, 2));
437 /* Return signed, long integers in [-2^31,2^31). */
438 extern int mrand48_r (struct drand48_data *__restrict __buffer,
439 long int *__restrict __result)
440 __THROW __nonnull ((1, 2));
441 extern int jrand48_r (unsigned short int __xsubi[3],
442 struct drand48_data *__restrict __buffer,
443 long int *__restrict __result)
444 __THROW __nonnull ((1, 2));
446 /* Seed random number generator. */
447 extern int srand48_r (long int __seedval, struct drand48_data *__buffer)
448 __THROW __nonnull ((2));
450 extern int seed48_r (unsigned short int __seed16v[3],
451 struct drand48_data *__buffer) __THROW __nonnull ((1, 2));
453 extern int lcong48_r (unsigned short int __param[7],
454 struct drand48_data *__buffer)
455 __THROW __nonnull ((1, 2));
456 # endif /* Use misc. */
457 #endif /* Use SVID or X/Open. */
459 #endif /* don't just need malloc and calloc */
461 #ifndef __malloc_and_calloc_defined
462 # define __malloc_and_calloc_defined
463 __BEGIN_NAMESPACE_STD
464 /* Allocate SIZE bytes of memory. */
465 extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
466 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
467 extern void *calloc (size_t __nmemb, size_t __size)
468 __THROW __attribute_malloc__ __wur;
469 __END_NAMESPACE_STD
470 #endif
472 #ifndef __need_malloc_and_calloc
473 __BEGIN_NAMESPACE_STD
474 /* Re-allocate the previously allocated block
475 in PTR, making the new block SIZE bytes long. */
476 /* __attribute_malloc__ is not used, because if realloc returns
477 the same pointer that was passed to it, aliasing needs to be allowed
478 between objects pointed by the old and new pointers. */
479 extern void *realloc (void *__ptr, size_t __size)
480 __THROW __attribute_warn_unused_result__;
481 /* Free a block allocated by `malloc', `realloc' or `calloc'. */
482 extern void free (void *__ptr) __THROW;
483 __END_NAMESPACE_STD
485 #ifdef __USE_MISC
486 /* Free a block. An alias for `free'. (Sun Unices). */
487 extern void cfree (void *__ptr) __THROW;
488 #endif /* Use misc. */
490 #if defined __USE_GNU || defined __USE_BSD || defined __USE_MISC
491 # include <alloca.h>
492 #endif /* Use GNU, BSD, or misc. */
494 #if (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K) \
495 || defined __USE_BSD
496 /* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */
497 extern void *valloc (size_t __size) __THROW __attribute_malloc__ __wur;
498 #endif
500 #ifdef __USE_XOPEN2K
501 /* Allocate memory of SIZE bytes with an alignment of ALIGNMENT. */
502 extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size)
503 __THROW __nonnull ((1)) __wur;
504 #endif
506 #ifdef __USE_ISOC11
507 /* ISO C variant of aligned allocation. */
508 extern void *aligned_alloc (size_t __alignment, size_t __size)
509 __THROW __wur __attribute__ ((__malloc__, __alloc_size__ (2)));
510 #endif
512 __BEGIN_NAMESPACE_STD
513 /* Abort execution and generate a core-dump. */
514 extern void abort (void) __THROW __attribute__ ((__noreturn__));
517 /* Register a function to be called when `exit' is called. */
518 extern int atexit (void (*__func) (void)) __THROW __nonnull ((1));
520 #if defined __USE_ISOC11 || defined __USE_ISOCXX11
521 /* Register a function to be called when `quick_exit' is called. */
522 # ifdef __cplusplus
523 extern "C++" int at_quick_exit (void (*__func) (void))
524 __THROW __asm ("at_quick_exit") __nonnull ((1));
525 # else
526 extern int at_quick_exit (void (*__func) (void)) __THROW __nonnull ((1));
527 # endif
528 #endif
529 __END_NAMESPACE_STD
531 #ifdef __USE_MISC
532 /* Register a function to be called with the status
533 given to `exit' and the given argument. */
534 extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg)
535 __THROW __nonnull ((1));
536 #endif
538 __BEGIN_NAMESPACE_STD
539 /* Call all functions registered with `atexit' and `on_exit',
540 in the reverse of the order in which they were registered,
541 perform stdio cleanup, and terminate program execution with STATUS. */
542 extern void exit (int __status) __THROW __attribute__ ((__noreturn__));
544 #if defined __USE_ISOC11 || defined __USE_ISOCXX11
545 /* Call all functions registered with `at_quick_exit' in the reverse
546 of the order in which they were registered and terminate program
547 execution with STATUS. */
548 extern void quick_exit (int __status) __THROW __attribute__ ((__noreturn__));
549 #endif
550 __END_NAMESPACE_STD
552 #ifdef __USE_ISOC99
553 __BEGIN_NAMESPACE_C99
554 /* Terminate the program with STATUS without calling any of the
555 functions registered with `atexit' or `on_exit'. */
556 extern void _Exit (int __status) __THROW __attribute__ ((__noreturn__));
557 __END_NAMESPACE_C99
558 #endif
561 __BEGIN_NAMESPACE_STD
562 /* Return the value of envariable NAME, or NULL if it doesn't exist. */
563 extern char *getenv (const char *__name) __THROW __nonnull ((1)) __wur;
564 __END_NAMESPACE_STD
566 #ifdef __USE_GNU
567 /* This function is similar to the above but returns NULL if the
568 programs is running with SUID or SGID enabled. */
569 extern char *secure_getenv (const char *__name)
570 __THROW __nonnull ((1)) __wur;
571 #endif
573 #if defined __USE_SVID || defined __USE_XOPEN
574 /* The SVID says this is in <stdio.h>, but this seems a better place. */
575 /* Put STRING, which is of the form "NAME=VALUE", in the environment.
576 If there is no `=', remove NAME from the environment. */
577 extern int putenv (char *__string) __THROW __nonnull ((1));
578 #endif
580 #if defined __USE_BSD || defined __USE_XOPEN2K
581 /* Set NAME to VALUE in the environment.
582 If REPLACE is nonzero, overwrite an existing value. */
583 extern int setenv (const char *__name, const char *__value, int __replace)
584 __THROW __nonnull ((2));
586 /* Remove the variable NAME from the environment. */
587 extern int unsetenv (const char *__name) __THROW __nonnull ((1));
588 #endif
590 #ifdef __USE_MISC
591 /* The `clearenv' was planned to be added to POSIX.1 but probably
592 never made it. Nevertheless the POSIX.9 standard (POSIX bindings
593 for Fortran 77) requires this function. */
594 extern int clearenv (void) __THROW;
595 #endif
598 #if defined __USE_MISC \
599 || (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8)
600 /* Generate a unique temporary file name from TEMPLATE.
601 The last six characters of TEMPLATE must be "XXXXXX";
602 they are replaced with a string that makes the file name unique.
603 Always returns TEMPLATE, it's either a temporary file name or a null
604 string if it cannot get a unique file name. */
605 extern char *mktemp (char *__template) __THROW __nonnull ((1));
606 #endif
608 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED \
609 || defined __USE_XOPEN2K8
610 /* Generate a unique temporary file name from TEMPLATE.
611 The last six characters of TEMPLATE must be "XXXXXX";
612 they are replaced with a string that makes the filename unique.
613 Returns a file descriptor open on the file for reading and writing,
614 or -1 if it cannot create a uniquely-named file.
616 This function is a possible cancellation point and therefore not
617 marked with __THROW. */
618 # ifndef __USE_FILE_OFFSET64
619 extern int mkstemp (char *__template) __nonnull ((1)) __wur;
620 # else
621 # ifdef __REDIRECT
622 extern int __REDIRECT (mkstemp, (char *__template), mkstemp64)
623 __nonnull ((1)) __wur;
624 # else
625 # define mkstemp mkstemp64
626 # endif
627 # endif
628 # ifdef __USE_LARGEFILE64
629 extern int mkstemp64 (char *__template) __nonnull ((1)) __wur;
630 # endif
631 #endif
633 #ifdef __USE_MISC
634 /* Similar to mkstemp, but the template can have a suffix after the
635 XXXXXX. The length of the suffix is specified in the second
636 parameter.
638 This function is a possible cancellation point and therefore not
639 marked with __THROW. */
640 # ifndef __USE_FILE_OFFSET64
641 extern int mkstemps (char *__template, int __suffixlen) __nonnull ((1)) __wur;
642 # else
643 # ifdef __REDIRECT
644 extern int __REDIRECT (mkstemps, (char *__template, int __suffixlen),
645 mkstemps64) __nonnull ((1)) __wur;
646 # else
647 # define mkstemps mkstemps64
648 # endif
649 # endif
650 # ifdef __USE_LARGEFILE64
651 extern int mkstemps64 (char *__template, int __suffixlen)
652 __nonnull ((1)) __wur;
653 # endif
654 #endif
656 #if defined __USE_BSD || defined __USE_XOPEN2K8
657 /* Create a unique temporary directory from TEMPLATE.
658 The last six characters of TEMPLATE must be "XXXXXX";
659 they are replaced with a string that makes the directory name unique.
660 Returns TEMPLATE, or a null pointer if it cannot get a unique name.
661 The directory is created mode 700. */
662 extern char *mkdtemp (char *__template) __THROW __nonnull ((1)) __wur;
663 #endif
665 #ifdef __USE_GNU
666 /* Generate a unique temporary file name from TEMPLATE similar to
667 mkstemp. But allow the caller to pass additional flags which are
668 used in the open call to create the file..
670 This function is a possible cancellation point and therefore not
671 marked with __THROW. */
672 # ifndef __USE_FILE_OFFSET64
673 extern int mkostemp (char *__template, int __flags) __nonnull ((1)) __wur;
674 # else
675 # ifdef __REDIRECT
676 extern int __REDIRECT (mkostemp, (char *__template, int __flags), mkostemp64)
677 __nonnull ((1)) __wur;
678 # else
679 # define mkostemp mkostemp64
680 # endif
681 # endif
682 # ifdef __USE_LARGEFILE64
683 extern int mkostemp64 (char *__template, int __flags) __nonnull ((1)) __wur;
684 # endif
686 /* Similar to mkostemp, but the template can have a suffix after the
687 XXXXXX. The length of the suffix is specified in the second
688 parameter.
690 This function is a possible cancellation point and therefore not
691 marked with __THROW. */
692 # ifndef __USE_FILE_OFFSET64
693 extern int mkostemps (char *__template, int __suffixlen, int __flags)
694 __nonnull ((1)) __wur;
695 # else
696 # ifdef __REDIRECT
697 extern int __REDIRECT (mkostemps, (char *__template, int __suffixlen,
698 int __flags), mkostemps64)
699 __nonnull ((1)) __wur;
700 # else
701 # define mkostemps mkostemps64
702 # endif
703 # endif
704 # ifdef __USE_LARGEFILE64
705 extern int mkostemps64 (char *__template, int __suffixlen, int __flags)
706 __nonnull ((1)) __wur;
707 # endif
708 #endif
711 __BEGIN_NAMESPACE_STD
712 /* Execute the given line as a shell command.
714 This function is a cancellation point and therefore not marked with
715 __THROW. */
716 extern int system (const char *__command) __wur;
717 __END_NAMESPACE_STD
720 #ifdef __USE_GNU
721 /* Return a malloc'd string containing the canonical absolute name of the
722 existing named file. */
723 extern char *canonicalize_file_name (const char *__name)
724 __THROW __nonnull ((1)) __wur;
725 #endif
727 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
728 /* Return the canonical absolute name of file NAME. If RESOLVED is
729 null, the result is malloc'd; otherwise, if the canonical name is
730 PATH_MAX chars or more, returns null with `errno' set to
731 ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars,
732 returns the name in RESOLVED. */
733 extern char *realpath (const char *__restrict __name,
734 char *__restrict __resolved) __THROW __wur;
735 #endif
738 /* Shorthand for type of comparison functions. */
739 #ifndef __COMPAR_FN_T
740 # define __COMPAR_FN_T
741 typedef int (*__compar_fn_t) (const void *, const void *);
743 # ifdef __USE_GNU
744 typedef __compar_fn_t comparison_fn_t;
745 # endif
746 #endif
747 #ifdef __USE_GNU
748 typedef int (*__compar_d_fn_t) (const void *, const void *, void *);
749 #endif
751 __BEGIN_NAMESPACE_STD
752 /* Do a binary search for KEY in BASE, which consists of NMEMB elements
753 of SIZE bytes each, using COMPAR to perform the comparisons. */
754 extern void *bsearch (const void *__key, const void *__base,
755 size_t __nmemb, size_t __size, __compar_fn_t __compar)
756 __nonnull ((1, 2, 5)) __wur;
758 /* Sort NMEMB elements of BASE, of SIZE bytes each,
759 using COMPAR to perform the comparisons. */
760 extern void qsort (void *__base, size_t __nmemb, size_t __size,
761 __compar_fn_t __compar) __nonnull ((1, 4));
762 #ifdef __USE_GNU
763 extern void qsort_r (void *__base, size_t __nmemb, size_t __size,
764 __compar_d_fn_t __compar, void *__arg)
765 __nonnull ((1, 4));
766 #endif
769 /* Return the absolute value of X. */
770 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
771 extern long int labs (long int __x) __THROW __attribute__ ((__const__)) __wur;
772 __END_NAMESPACE_STD
774 #ifdef __USE_ISOC99
775 __extension__ extern long long int llabs (long long int __x)
776 __THROW __attribute__ ((__const__)) __wur;
777 #endif
780 __BEGIN_NAMESPACE_STD
781 /* Return the `div_t', `ldiv_t' or `lldiv_t' representation
782 of the value of NUMER over DENOM. */
783 /* GCC may have built-ins for these someday. */
784 extern div_t div (int __numer, int __denom)
785 __THROW __attribute__ ((__const__)) __wur;
786 extern ldiv_t ldiv (long int __numer, long int __denom)
787 __THROW __attribute__ ((__const__)) __wur;
788 __END_NAMESPACE_STD
790 #ifdef __USE_ISOC99
791 __BEGIN_NAMESPACE_C99
792 __extension__ extern lldiv_t lldiv (long long int __numer,
793 long long int __denom)
794 __THROW __attribute__ ((__const__)) __wur;
795 __END_NAMESPACE_C99
796 #endif
799 #if (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8) \
800 || defined __USE_SVID
801 /* Convert floating point numbers to strings. The returned values are
802 valid only until another call to the same function. */
804 /* Convert VALUE to a string with NDIGIT digits and return a pointer to
805 this. Set *DECPT with the position of the decimal character and *SIGN
806 with the sign of the number. */
807 extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt,
808 int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur;
810 /* Convert VALUE to a string rounded to NDIGIT decimal digits. Set *DECPT
811 with the position of the decimal character and *SIGN with the sign of
812 the number. */
813 extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt,
814 int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur;
816 /* If possible convert VALUE to a string with NDIGIT significant digits.
817 Otherwise use exponential representation. The resulting string will
818 be written to BUF. */
819 extern char *gcvt (double __value, int __ndigit, char *__buf)
820 __THROW __nonnull ((3)) __wur;
823 # ifdef __USE_MISC
824 /* Long double versions of above functions. */
825 extern char *qecvt (long double __value, int __ndigit,
826 int *__restrict __decpt, int *__restrict __sign)
827 __THROW __nonnull ((3, 4)) __wur;
828 extern char *qfcvt (long double __value, int __ndigit,
829 int *__restrict __decpt, int *__restrict __sign)
830 __THROW __nonnull ((3, 4)) __wur;
831 extern char *qgcvt (long double __value, int __ndigit, char *__buf)
832 __THROW __nonnull ((3)) __wur;
835 /* Reentrant version of the functions above which provide their own
836 buffers. */
837 extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt,
838 int *__restrict __sign, char *__restrict __buf,
839 size_t __len) __THROW __nonnull ((3, 4, 5));
840 extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt,
841 int *__restrict __sign, char *__restrict __buf,
842 size_t __len) __THROW __nonnull ((3, 4, 5));
844 extern int qecvt_r (long double __value, int __ndigit,
845 int *__restrict __decpt, int *__restrict __sign,
846 char *__restrict __buf, size_t __len)
847 __THROW __nonnull ((3, 4, 5));
848 extern int qfcvt_r (long double __value, int __ndigit,
849 int *__restrict __decpt, int *__restrict __sign,
850 char *__restrict __buf, size_t __len)
851 __THROW __nonnull ((3, 4, 5));
852 # endif /* misc */
853 #endif /* use MISC || use X/Open Unix */
856 __BEGIN_NAMESPACE_STD
857 /* Return the length of the multibyte character
858 in S, which is no longer than N. */
859 extern int mblen (const char *__s, size_t __n) __THROW __wur;
860 /* Return the length of the given multibyte character,
861 putting its `wchar_t' representation in *PWC. */
862 extern int mbtowc (wchar_t *__restrict __pwc,
863 const char *__restrict __s, size_t __n) __THROW __wur;
864 /* Put the multibyte character represented
865 by WCHAR in S, returning its length. */
866 extern int wctomb (char *__s, wchar_t __wchar) __THROW __wur;
869 /* Convert a multibyte string to a wide char string. */
870 extern size_t mbstowcs (wchar_t *__restrict __pwcs,
871 const char *__restrict __s, size_t __n) __THROW;
872 /* Convert a wide char string to multibyte string. */
873 extern size_t wcstombs (char *__restrict __s,
874 const wchar_t *__restrict __pwcs, size_t __n)
875 __THROW;
876 __END_NAMESPACE_STD
879 #ifdef __USE_SVID
880 /* Determine whether the string value of RESPONSE matches the affirmation
881 or negative response expression as specified by the LC_MESSAGES category
882 in the program's current locale. Returns 1 if affirmative, 0 if
883 negative, and -1 if not matching. */
884 extern int rpmatch (const char *__response) __THROW __nonnull ((1)) __wur;
885 #endif
888 #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
889 /* Parse comma separated suboption from *OPTIONP and match against
890 strings in TOKENS. If found return index and set *VALUEP to
891 optional value introduced by an equal sign. If the suboption is
892 not part of TOKENS return in *VALUEP beginning of unknown
893 suboption. On exit *OPTIONP is set to the beginning of the next
894 token or at the terminating NUL character. */
895 extern int getsubopt (char **__restrict __optionp,
896 char *const *__restrict __tokens,
897 char **__restrict __valuep)
898 __THROW __nonnull ((1, 2, 3)) __wur;
899 #endif
902 #ifdef __USE_XOPEN
903 /* Setup DES tables according KEY. */
904 extern void setkey (const char *__key) __THROW __nonnull ((1));
905 #endif
908 /* X/Open pseudo terminal handling. */
910 #ifdef __USE_XOPEN2KXSI
911 /* Return a master pseudo-terminal handle. */
912 extern int posix_openpt (int __oflag) __wur;
913 #endif
915 #ifdef __USE_XOPEN
916 /* The next four functions all take a master pseudo-tty fd and
917 perform an operation on the associated slave: */
919 /* Chown the slave to the calling user. */
920 extern int grantpt (int __fd) __THROW;
922 /* Release an internal lock so the slave can be opened.
923 Call after grantpt(). */
924 extern int unlockpt (int __fd) __THROW;
926 /* Return the pathname of the pseudo terminal slave assoicated with
927 the master FD is open on, or NULL on errors.
928 The returned storage is good until the next call to this function. */
929 extern char *ptsname (int __fd) __THROW __wur;
930 #endif
932 #ifdef __USE_GNU
933 /* Store at most BUFLEN characters of the pathname of the slave pseudo
934 terminal associated with the master FD is open on in BUF.
935 Return 0 on success, otherwise an error number. */
936 extern int ptsname_r (int __fd, char *__buf, size_t __buflen)
937 __THROW __nonnull ((2));
939 /* Open a master pseudo terminal and return its file descriptor. */
940 extern int getpt (void);
941 #endif
943 #ifdef __USE_BSD
944 /* Put the 1 minute, 5 minute and 15 minute load averages into the first
945 NELEM elements of LOADAVG. Return the number written (never more than
946 three, but may be less than NELEM), or -1 if an error occurred. */
947 extern int getloadavg (double __loadavg[], int __nelem)
948 __THROW __nonnull ((1));
949 #endif
951 #include <bits/stdlib-float.h>
953 /* Define some macros helping to catch buffer overflows. */
954 #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
955 # include <bits/stdlib.h>
956 #endif
957 #ifdef __LDBL_COMPAT
958 # include <bits/stdlib-ldbl.h>
959 #endif
961 #endif /* don't just need malloc and calloc */
962 #undef __need_malloc_and_calloc
964 __END_DECLS
966 #endif /* stdlib.h */