(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / stdlib / stdlib.h
blob1bda32262bc4e74158ed21c3c362e0e61d16cd92
1 /* Copyright (C) 1991-2002, 2003, 2004 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, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
20 * ISO C99 Standard: 7.20 General utilities <stdlib.h>
23 #ifndef _STDLIB_H
25 #include <features.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 _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 # ifdef __USE_BSD
47 /* Lots of hair to allow traditional BSD use of `union wait'
48 as well as POSIX.1 use of `int' for the status word. */
50 # if defined __GNUC__ && !defined __cplusplus
51 # define __WAIT_INT(status) \
52 (__extension__ ({ union { __typeof(status) __in; int __i; } __u; \
53 __u.__in = (status); __u.__i; }))
54 # else
55 # define __WAIT_INT(status) (*(int *) &(status))
56 # endif
58 /* This is the type of the argument to `wait'. The funky union
59 causes redeclarations with ether `int *' or `union wait *' to be
60 allowed without complaint. __WAIT_STATUS_DEFN is the type used in
61 the actual function definitions. */
63 # if !defined __GNUC__ || __GNUC__ < 2 || defined __cplusplus
64 # define __WAIT_STATUS void *
65 # define __WAIT_STATUS_DEFN void *
66 # else
67 /* This works in GCC 2.6.1 and later. */
68 typedef union
70 union wait *__uptr;
71 int *__iptr;
72 } __WAIT_STATUS __attribute__ ((__transparent_union__));
73 # define __WAIT_STATUS_DEFN int *
74 # endif
76 # else /* Don't use BSD. */
78 # define __WAIT_INT(status) (status)
79 # define __WAIT_STATUS int *
80 # define __WAIT_STATUS_DEFN int *
82 # endif /* Use BSD. */
84 /* Define the macros <sys/wait.h> also would define this way. */
85 # define WEXITSTATUS(status) __WEXITSTATUS(__WAIT_INT(status))
86 # define WTERMSIG(status) __WTERMSIG(__WAIT_INT(status))
87 # define WSTOPSIG(status) __WSTOPSIG(__WAIT_INT(status))
88 # define WIFEXITED(status) __WIFEXITED(__WAIT_INT(status))
89 # define WIFSIGNALED(status) __WIFSIGNALED(__WAIT_INT(status))
90 # define WIFSTOPPED(status) __WIFSTOPPED(__WAIT_INT(status))
91 # ifdef __WIFCONTINUED
92 # define WIFCONTINUED(status) __WIFCONTINUED(__WAIT_INT(status))
93 # endif
94 #endif /* X/Open and <sys/wait.h> not included. */
96 __BEGIN_NAMESPACE_STD
97 /* Returned by `div'. */
98 typedef struct
100 int quot; /* Quotient. */
101 int rem; /* Remainder. */
102 } div_t;
104 /* Returned by `ldiv'. */
105 #ifndef __ldiv_t_defined
106 typedef struct
108 long int quot; /* Quotient. */
109 long int rem; /* Remainder. */
110 } ldiv_t;
111 # define __ldiv_t_defined 1
112 #endif
113 __END_NAMESPACE_STD
115 #if defined __USE_ISOC99 && !defined __lldiv_t_defined
116 __BEGIN_NAMESPACE_C99
117 /* Returned by `lldiv'. */
118 __extension__ typedef struct
120 long long int quot; /* Quotient. */
121 long long int rem; /* Remainder. */
122 } lldiv_t;
123 # define __lldiv_t_defined 1
124 __END_NAMESPACE_C99
125 #endif
128 /* The largest number rand will return (same as INT_MAX). */
129 #define RAND_MAX 2147483647
132 /* We define these the same for all machines.
133 Changes from this to the outside world should be done in `_exit'. */
134 #define EXIT_FAILURE 1 /* Failing exit status. */
135 #define EXIT_SUCCESS 0 /* Successful exit status. */
138 /* Maximum length of a multibyte character in the current locale. */
139 #define MB_CUR_MAX (__ctype_get_mb_cur_max ())
140 extern size_t __ctype_get_mb_cur_max (void) __THROW;
143 __BEGIN_NAMESPACE_STD
144 /* Convert a string to a floating-point number. */
145 extern double atof (__const char *__nptr)
146 __THROW __attribute_pure__ __nonnull ((1));
147 /* Convert a string to an integer. */
148 extern int atoi (__const char *__nptr)
149 __THROW __attribute_pure__ __nonnull ((1));
150 /* Convert a string to a long integer. */
151 extern long int atol (__const char *__nptr)
152 __THROW __attribute_pure__ __nonnull ((1));
153 __END_NAMESPACE_STD
155 #if defined __USE_ISOC99 || (defined __GLIBC_HAVE_LONG_LONG && defined __USE_MISC)
156 __BEGIN_NAMESPACE_C99
157 /* Convert a string to a long long integer. */
158 __extension__ extern long long int atoll (__const char *__nptr)
159 __THROW __attribute_pure__ __nonnull ((1));
160 __END_NAMESPACE_C99
161 #endif
163 __BEGIN_NAMESPACE_STD
164 /* Convert a string to a floating-point number. */
165 extern double strtod (__const char *__restrict __nptr,
166 char **__restrict __endptr) __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_C99
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 application is
225 the implementation of the internationalization handling in the
226 upcoming ISO C++ standard library. To support this another set of
227 the functions using locale data exist which have an additional
228 argument.
230 Attention: all these functions are *not* standardized in any form.
231 This is a proof-of-concept implementation. */
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) __THROW __nonnull ((1, 3));
271 #endif /* GNU */
274 /* The internal entry points for `strtoX' take an extra flag argument
275 saying whether or not to parse locale-dependent number grouping. */
277 extern double __strtod_internal (__const char *__restrict __nptr,
278 char **__restrict __endptr, int __group)
279 __THROW __nonnull ((1));
280 extern float __strtof_internal (__const char *__restrict __nptr,
281 char **__restrict __endptr, int __group)
282 __THROW __nonnull ((1));
283 extern long double __strtold_internal (__const char *__restrict __nptr,
284 char **__restrict __endptr,
285 int __group) __THROW __nonnull ((1));
286 #ifndef __strtol_internal_defined
287 extern long int __strtol_internal (__const char *__restrict __nptr,
288 char **__restrict __endptr,
289 int __base, int __group)
290 __THROW __nonnull ((1));
291 # define __strtol_internal_defined 1
292 #endif
293 #ifndef __strtoul_internal_defined
294 extern unsigned long int __strtoul_internal (__const char *__restrict __nptr,
295 char **__restrict __endptr,
296 int __base, int __group)
297 __THROW __nonnull ((1));
298 # define __strtoul_internal_defined 1
299 #endif
300 #if defined __GNUC__ || defined __USE_ISOC99
301 # ifndef __strtoll_internal_defined
302 __extension__
303 extern long long int __strtoll_internal (__const char *__restrict __nptr,
304 char **__restrict __endptr,
305 int __base, int __group)
306 __THROW __nonnull ((1));
307 # define __strtoll_internal_defined 1
308 # endif
309 # ifndef __strtoull_internal_defined
310 __extension__
311 extern unsigned long long int __strtoull_internal (__const char *
312 __restrict __nptr,
313 char **__restrict __endptr,
314 int __base, int __group)
315 __THROW __nonnull ((1));
316 # define __strtoull_internal_defined 1
317 # endif
318 #endif /* GCC */
320 #ifdef __USE_EXTERN_INLINES
321 /* Define inline functions which call the internal entry points. */
323 __BEGIN_NAMESPACE_STD
324 extern __inline double
325 __NTH (strtod (__const char *__restrict __nptr, char **__restrict __endptr))
327 return __strtod_internal (__nptr, __endptr, 0);
329 extern __inline long int
330 __NTH (strtol (__const char *__restrict __nptr, char **__restrict __endptr,
331 int __base))
333 return __strtol_internal (__nptr, __endptr, __base, 0);
335 extern __inline unsigned long int
336 __NTH (strtoul (__const char *__restrict __nptr, char **__restrict __endptr,
337 int __base))
339 return __strtoul_internal (__nptr, __endptr, __base, 0);
341 __END_NAMESPACE_STD
343 # ifdef __USE_ISOC99
344 __BEGIN_NAMESPACE_C99
345 extern __inline float
346 __NTH (strtof (__const char *__restrict __nptr, char **__restrict __endptr))
348 return __strtof_internal (__nptr, __endptr, 0);
350 extern __inline long double
351 __NTH (strtold (__const char *__restrict __nptr, char **__restrict __endptr))
353 return __strtold_internal (__nptr, __endptr, 0);
355 __END_NAMESPACE_C99
356 # endif
358 # ifdef __USE_BSD
359 __extension__ extern __inline long long int
360 __NTH (strtoq (__const char *__restrict __nptr, char **__restrict __endptr,
361 int __base))
363 return __strtoll_internal (__nptr, __endptr, __base, 0);
365 __extension__ extern __inline unsigned long long int
366 __NTH (strtouq (__const char *__restrict __nptr, char **__restrict __endptr,
367 int __base))
369 return __strtoull_internal (__nptr, __endptr, __base, 0);
371 # endif
373 # if defined __USE_MISC || defined __USE_ISOC99
374 __BEGIN_NAMESPACE_C99
375 __extension__ extern __inline long long int
376 __NTH (strtoll (__const char *__restrict __nptr, char **__restrict __endptr,
377 int __base))
379 return __strtoll_internal (__nptr, __endptr, __base, 0);
381 __extension__ extern __inline unsigned long long int
382 __NTH (strtoull (__const char * __restrict __nptr, char **__restrict __endptr,
383 int __base))
385 return __strtoull_internal (__nptr, __endptr, __base, 0);
387 __END_NAMESPACE_C99
388 # endif
390 __BEGIN_NAMESPACE_STD
391 extern __inline double
392 __NTH (atof (__const char *__nptr))
394 return strtod (__nptr, (char **) NULL);
396 extern __inline int
397 __NTH (atoi (__const char *__nptr))
399 return (int) strtol (__nptr, (char **) NULL, 10);
401 extern __inline long int
402 __NTH (atol (__const char *__nptr))
404 return strtol (__nptr, (char **) NULL, 10);
406 __END_NAMESPACE_STD
408 # if defined __USE_MISC || defined __USE_ISOC99
409 __BEGIN_NAMESPACE_C99
410 __extension__ extern __inline long long int
411 __NTH (atoll (__const char *__nptr))
413 return strtoll (__nptr, (char **) NULL, 10);
415 __END_NAMESPACE_C99
416 # endif
417 #endif /* Optimizing and Inlining. */
420 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED
421 /* Convert N to base 64 using the digits "./0-9A-Za-z", least-significant
422 digit first. Returns a pointer to static storage overwritten by the
423 next call. */
424 extern char *l64a (long int __n) __THROW;
426 /* Read a number from a string S in base 64 as above. */
427 extern long int a64l (__const char *__s)
428 __THROW __attribute_pure__ __nonnull ((1));
430 #endif /* Use SVID || extended X/Open. */
432 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED || defined __USE_BSD
433 # include <sys/types.h> /* we need int32_t... */
435 /* These are the functions that actually do things. The `random', `srandom',
436 `initstate' and `setstate' functions are those from BSD Unices.
437 The `rand' and `srand' functions are required by the ANSI standard.
438 We provide both interfaces to the same random number generator. */
439 /* Return a random long integer between 0 and RAND_MAX inclusive. */
440 extern long int random (void) __THROW;
442 /* Seed the random number generator with the given number. */
443 extern void srandom (unsigned int __seed) __THROW;
445 /* Initialize the random number generator to use state buffer STATEBUF,
446 of length STATELEN, and seed it with SEED. Optimal lengths are 8, 16,
447 32, 64, 128 and 256, the bigger the better; values less than 8 will
448 cause an error and values greater than 256 will be rounded down. */
449 extern char *initstate (unsigned int __seed, char *__statebuf,
450 size_t __statelen) __THROW __nonnull ((2));
452 /* Switch the random number generator to state buffer STATEBUF,
453 which should have been previously initialized by `initstate'. */
454 extern char *setstate (char *__statebuf) __THROW __nonnull ((1));
457 # ifdef __USE_MISC
458 /* Reentrant versions of the `random' family of functions.
459 These functions all use the following data structure to contain
460 state, rather than global state variables. */
462 struct random_data
464 int32_t *fptr; /* Front pointer. */
465 int32_t *rptr; /* Rear pointer. */
466 int32_t *state; /* Array of state values. */
467 int rand_type; /* Type of random number generator. */
468 int rand_deg; /* Degree of random number generator. */
469 int rand_sep; /* Distance between front and rear. */
470 int32_t *end_ptr; /* Pointer behind state table. */
473 extern int random_r (struct random_data *__restrict __buf,
474 int32_t *__restrict __result) __THROW __nonnull ((1, 2));
476 extern int srandom_r (unsigned int __seed, struct random_data *__buf)
477 __THROW __nonnull ((2));
479 extern int initstate_r (unsigned int __seed, char *__restrict __statebuf,
480 size_t __statelen,
481 struct random_data *__restrict __buf)
482 __THROW __nonnull ((2, 4));
484 extern int setstate_r (char *__restrict __statebuf,
485 struct random_data *__restrict __buf)
486 __THROW __nonnull ((1, 2));
487 # endif /* Use misc. */
488 #endif /* Use SVID || extended X/Open || BSD. */
491 __BEGIN_NAMESPACE_STD
492 /* Return a random integer between 0 and RAND_MAX inclusive. */
493 extern int rand (void) __THROW;
494 /* Seed the random number generator with the given number. */
495 extern void srand (unsigned int __seed) __THROW;
496 __END_NAMESPACE_STD
498 #ifdef __USE_POSIX
499 /* Reentrant interface according to POSIX.1. */
500 extern int rand_r (unsigned int *__seed) __THROW;
501 #endif
504 #if defined __USE_SVID || defined __USE_XOPEN
505 /* System V style 48-bit random number generator functions. */
507 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
508 extern double drand48 (void) __THROW;
509 extern double erand48 (unsigned short int __xsubi[3]) __THROW __nonnull ((1));
511 /* Return non-negative, long integer in [0,2^31). */
512 extern long int lrand48 (void) __THROW;
513 extern long int nrand48 (unsigned short int __xsubi[3])
514 __THROW __nonnull ((1));
516 /* Return signed, long integers in [-2^31,2^31). */
517 extern long int mrand48 (void) __THROW;
518 extern long int jrand48 (unsigned short int __xsubi[3])
519 __THROW __nonnull ((1));
521 /* Seed random number generator. */
522 extern void srand48 (long int __seedval) __THROW;
523 extern unsigned short int *seed48 (unsigned short int __seed16v[3])
524 __THROW __nonnull ((1));
525 extern void lcong48 (unsigned short int __param[7]) __THROW __nonnull ((1));
527 # ifdef __USE_MISC
528 /* Data structure for communication with thread safe versions. This
529 type is to be regarded as opaque. It's only exported because users
530 have to allocate objects of this type. */
531 struct drand48_data
533 unsigned short int __x[3]; /* Current state. */
534 unsigned short int __old_x[3]; /* Old state. */
535 unsigned short int __c; /* Additive const. in congruential formula. */
536 unsigned short int __init; /* Flag for initializing. */
537 unsigned long long int __a; /* Factor in congruential formula. */
540 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
541 extern int drand48_r (struct drand48_data *__restrict __buffer,
542 double *__restrict __result) __THROW __nonnull ((1, 2));
543 extern int erand48_r (unsigned short int __xsubi[3],
544 struct drand48_data *__restrict __buffer,
545 double *__restrict __result) __THROW __nonnull ((1, 2));
547 /* Return non-negative, long integer in [0,2^31). */
548 extern int lrand48_r (struct drand48_data *__restrict __buffer,
549 long int *__restrict __result)
550 __THROW __nonnull ((1, 2));
551 extern int nrand48_r (unsigned short int __xsubi[3],
552 struct drand48_data *__restrict __buffer,
553 long int *__restrict __result)
554 __THROW __nonnull ((1, 2));
556 /* Return signed, long integers in [-2^31,2^31). */
557 extern int mrand48_r (struct drand48_data *__restrict __buffer,
558 long int *__restrict __result)
559 __THROW __nonnull ((1, 2));
560 extern int jrand48_r (unsigned short int __xsubi[3],
561 struct drand48_data *__restrict __buffer,
562 long int *__restrict __result)
563 __THROW __nonnull ((1, 2));
565 /* Seed random number generator. */
566 extern int srand48_r (long int __seedval, struct drand48_data *__buffer)
567 __THROW __nonnull ((2));
569 extern int seed48_r (unsigned short int __seed16v[3],
570 struct drand48_data *__buffer) __THROW __nonnull ((1, 2));
572 extern int lcong48_r (unsigned short int __param[7],
573 struct drand48_data *__buffer)
574 __THROW __nonnull ((1, 2));
575 # endif /* Use misc. */
576 #endif /* Use SVID or X/Open. */
578 #endif /* don't just need malloc and calloc */
580 #ifndef __malloc_and_calloc_defined
581 # define __malloc_and_calloc_defined
582 __BEGIN_NAMESPACE_STD
583 /* Allocate SIZE bytes of memory. */
584 extern void *malloc (size_t __size) __THROW __attribute_malloc__;
585 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
586 extern void *calloc (size_t __nmemb, size_t __size)
587 __THROW __attribute_malloc__;
588 __END_NAMESPACE_STD
589 #endif
591 #ifndef __need_malloc_and_calloc
592 __BEGIN_NAMESPACE_STD
593 /* Re-allocate the previously allocated block
594 in PTR, making the new block SIZE bytes long. */
595 extern void *realloc (void *__ptr, size_t __size) __THROW __attribute_malloc__;
596 /* Free a block allocated by `malloc', `realloc' or `calloc'. */
597 extern void free (void *__ptr) __THROW;
598 __END_NAMESPACE_STD
600 #ifdef __USE_MISC
601 /* Free a block. An alias for `free'. (Sun Unices). */
602 extern void cfree (void *__ptr) __THROW;
603 #endif /* Use misc. */
605 #if defined __USE_GNU || defined __USE_BSD || defined __USE_MISC
606 # include <alloca.h>
607 #endif /* Use GNU, BSD, or misc. */
609 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
610 /* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */
611 extern void *valloc (size_t __size) __THROW __attribute_malloc__;
612 #endif
614 #ifdef __USE_XOPEN2K
615 /* Allocate memory of SIZE bytes with an alignment of ALIGNMENT. */
616 extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size)
617 __THROW __attribute_malloc__ __nonnull ((1));
618 #endif
620 __BEGIN_NAMESPACE_STD
621 /* Abort execution and generate a core-dump. */
622 extern void abort (void) __THROW __attribute__ ((__noreturn__));
625 /* Register a function to be called when `exit' is called. */
626 extern int atexit (void (*__func) (void)) __THROW __nonnull ((1));
627 __END_NAMESPACE_STD
629 #ifdef __USE_MISC
630 /* Register a function to be called with the status
631 given to `exit' and the given argument. */
632 extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg)
633 __THROW __nonnull ((1));
634 #endif
636 __BEGIN_NAMESPACE_STD
637 /* Call all functions registered with `atexit' and `on_exit',
638 in the reverse of the order in which they were registered
639 perform stdio cleanup, and terminate program execution with STATUS. */
640 extern void exit (int __status) __THROW __attribute__ ((__noreturn__));
641 __END_NAMESPACE_STD
643 #ifdef __USE_ISOC99
644 __BEGIN_NAMESPACE_C99
645 /* Terminate the program with STATUS without calling any of the
646 functions registered with `atexit' or `on_exit'. */
647 extern void _Exit (int __status) __THROW __attribute__ ((__noreturn__));
648 __END_NAMESPACE_C99
649 #endif
652 __BEGIN_NAMESPACE_STD
653 /* Return the value of envariable NAME, or NULL if it doesn't exist. */
654 extern char *getenv (__const char *__name) __THROW __nonnull ((1));
655 __END_NAMESPACE_STD
657 /* This function is similar to the above but returns NULL if the
658 programs is running with SUID or SGID enabled. */
659 extern char *__secure_getenv (__const char *__name) __THROW __nonnull ((1));
661 #if defined __USE_SVID || defined __USE_XOPEN
662 /* The SVID says this is in <stdio.h>, but this seems a better place. */
663 /* Put STRING, which is of the form "NAME=VALUE", in the environment.
664 If there is no `=', remove NAME from the environment. */
665 extern int putenv (char *__string) __THROW __nonnull ((1));
666 #endif
668 #if defined __USE_BSD || defined __USE_XOPEN2K
669 /* Set NAME to VALUE in the environment.
670 If REPLACE is nonzero, overwrite an existing value. */
671 extern int setenv (__const char *__name, __const char *__value, int __replace)
672 __THROW __nonnull ((2));
674 /* Remove the variable NAME from the environment. */
675 extern int unsetenv (__const char *__name) __THROW;
676 #endif
678 #ifdef __USE_MISC
679 /* The `clearenv' was planned to be added to POSIX.1 but probably
680 never made it. Nevertheless the POSIX.9 standard (POSIX bindings
681 for Fortran 77) requires this function. */
682 extern int clearenv (void) __THROW;
683 #endif
686 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
687 /* Generate a unique temporary file name from TEMPLATE.
688 The last six characters of TEMPLATE must be "XXXXXX";
689 they are replaced with a string that makes the file name unique.
690 Returns TEMPLATE, or a null pointer if it cannot get a unique file name. */
691 extern char *mktemp (char *__template) __THROW __nonnull ((1));
693 /* Generate a unique temporary file name from TEMPLATE.
694 The last six characters of TEMPLATE must be "XXXXXX";
695 they are replaced with a string that makes the filename unique.
696 Returns a file descriptor open on the file for reading and writing,
697 or -1 if it cannot create a uniquely-named file.
699 This function is a possible cancellation points and therefore not
700 marked with __THROW. */
701 # ifndef __USE_FILE_OFFSET64
702 extern int mkstemp (char *__template) __nonnull ((1));
703 # else
704 # ifdef __REDIRECT
705 extern int __REDIRECT (mkstemp, (char *__template), mkstemp64) __nonnull ((1));
706 # else
707 # define mkstemp mkstemp64
708 # endif
709 # endif
710 # ifdef __USE_LARGEFILE64
711 extern int mkstemp64 (char *__template) __nonnull ((1));
712 # endif
713 #endif
715 #ifdef __USE_BSD
716 /* Create a unique temporary directory from TEMPLATE.
717 The last six characters of TEMPLATE must be "XXXXXX";
718 they are replaced with a string that makes the directory name unique.
719 Returns TEMPLATE, or a null pointer if it cannot get a unique name.
720 The directory is created mode 700. */
721 extern char *mkdtemp (char *__template) __THROW __nonnull ((1));
722 #endif
725 __BEGIN_NAMESPACE_STD
726 /* Execute the given line as a shell command.
728 This function is a cancellation point and therefore not marked with
729 __THROW. */
730 extern int system (__const char *__command);
731 __END_NAMESPACE_STD
734 #ifdef __USE_GNU
735 /* Return a malloc'd string containing the canonical absolute name of the
736 named file. The last file name component need not exist, and may be a
737 symlink to a nonexistent file. */
738 extern char *canonicalize_file_name (__const char *__name)
739 __THROW __nonnull ((1));
740 #endif
742 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
743 /* Return the canonical absolute name of file NAME. The last file name
744 component need not exist, and may be a symlink to a nonexistent file.
745 If RESOLVED is null, the result is malloc'd; otherwise, if the canonical
746 name is PATH_MAX chars or more, returns null with `errno' set to
747 ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, returns the
748 name in RESOLVED. */
749 extern char *realpath (__const char *__restrict __name,
750 char *__restrict __resolved) __THROW;
751 #endif
754 /* Shorthand for type of comparison functions. */
755 #ifndef __COMPAR_FN_T
756 # define __COMPAR_FN_T
757 typedef int (*__compar_fn_t) (__const void *, __const void *);
759 # ifdef __USE_GNU
760 typedef __compar_fn_t comparison_fn_t;
761 # endif
762 #endif
764 __BEGIN_NAMESPACE_STD
765 /* Do a binary search for KEY in BASE, which consists of NMEMB elements
766 of SIZE bytes each, using COMPAR to perform the comparisons. */
767 extern void *bsearch (__const void *__key, __const void *__base,
768 size_t __nmemb, size_t __size, __compar_fn_t __compar)
769 __nonnull ((1, 2, 5));
771 /* Sort NMEMB elements of BASE, of SIZE bytes each,
772 using COMPAR to perform the comparisons. */
773 extern void qsort (void *__base, size_t __nmemb, size_t __size,
774 __compar_fn_t __compar) __nonnull ((1, 4));
777 /* Return the absolute value of X. */
778 extern int abs (int __x) __THROW __attribute__ ((__const__));
779 extern long int labs (long int __x) __THROW __attribute__ ((__const__));
780 __END_NAMESPACE_STD
782 #ifdef __USE_ISOC99
783 __extension__ extern long long int llabs (long long int __x)
784 __THROW __attribute__ ((__const__));
785 #endif
788 __BEGIN_NAMESPACE_STD
789 /* Return the `div_t', `ldiv_t' or `lldiv_t' representation
790 of the value of NUMER over DENOM. */
791 /* GCC may have built-ins for these someday. */
792 extern div_t div (int __numer, int __denom)
793 __THROW __attribute__ ((__const__));
794 extern ldiv_t ldiv (long int __numer, long int __denom)
795 __THROW __attribute__ ((__const__));
796 __END_NAMESPACE_STD
798 #ifdef __USE_ISOC99
799 __BEGIN_NAMESPACE_C99
800 __extension__ extern lldiv_t lldiv (long long int __numer,
801 long long int __denom)
802 __THROW __attribute__ ((__const__));
803 __END_NAMESPACE_C99
804 #endif
807 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED
808 /* Convert floating point numbers to strings. The returned values are
809 valid only until another call to the same function. */
811 /* Convert VALUE to a string with NDIGIT digits and return a pointer to
812 this. Set *DECPT with the position of the decimal character and *SIGN
813 with the sign of the number. */
814 extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt,
815 int *__restrict __sign) __THROW __nonnull ((3, 4));
817 /* Convert VALUE to a string rounded to NDIGIT decimal digits. Set *DECPT
818 with the position of the decimal character and *SIGN with the sign of
819 the number. */
820 extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt,
821 int *__restrict __sign) __THROW __nonnull ((3, 4));
823 /* If possible convert VALUE to a string with NDIGIT significant digits.
824 Otherwise use exponential representation. The resulting string will
825 be written to BUF. */
826 extern char *gcvt (double __value, int __ndigit, char *__buf)
827 __THROW __nonnull ((3));
830 # ifdef __USE_MISC
831 /* Long double versions of above functions. */
832 extern char *qecvt (long double __value, int __ndigit,
833 int *__restrict __decpt, int *__restrict __sign)
834 __THROW __nonnull ((3, 4));
835 extern char *qfcvt (long double __value, int __ndigit,
836 int *__restrict __decpt, int *__restrict __sign)
837 __THROW __nonnull ((3, 4));
838 extern char *qgcvt (long double __value, int __ndigit, char *__buf)
839 __THROW __nonnull ((3));
842 /* Reentrant version of the functions above which provide their own
843 buffers. */
844 extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt,
845 int *__restrict __sign, char *__restrict __buf,
846 size_t __len) __THROW __nonnull ((3, 4, 5));
847 extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt,
848 int *__restrict __sign, char *__restrict __buf,
849 size_t __len) __THROW __nonnull ((3, 4, 5));
851 extern int qecvt_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 extern int qfcvt_r (long double __value, int __ndigit,
856 int *__restrict __decpt, int *__restrict __sign,
857 char *__restrict __buf, size_t __len)
858 __THROW __nonnull ((3, 4, 5));
859 # endif /* misc */
860 #endif /* use MISC || use X/Open Unix */
863 __BEGIN_NAMESPACE_STD
864 /* Return the length of the multibyte character
865 in S, which is no longer than N. */
866 extern int mblen (__const char *__s, size_t __n) __THROW;
867 /* Return the length of the given multibyte character,
868 putting its `wchar_t' representation in *PWC. */
869 extern int mbtowc (wchar_t *__restrict __pwc,
870 __const char *__restrict __s, size_t __n) __THROW;
871 /* Put the multibyte character represented
872 by WCHAR in S, returning its length. */
873 extern int wctomb (char *__s, wchar_t __wchar) __THROW;
876 /* Convert a multibyte string to a wide char string. */
877 extern size_t mbstowcs (wchar_t *__restrict __pwcs,
878 __const char *__restrict __s, size_t __n) __THROW;
879 /* Convert a wide char string to multibyte string. */
880 extern size_t wcstombs (char *__restrict __s,
881 __const wchar_t *__restrict __pwcs, size_t __n)
882 __THROW;
883 __END_NAMESPACE_STD
886 #ifdef __USE_SVID
887 /* Determine whether the string value of RESPONSE matches the affirmation
888 or negative response expression as specified by the LC_MESSAGES category
889 in the program's current locale. Returns 1 if affirmative, 0 if
890 negative, and -1 if not matching. */
891 extern int rpmatch (__const char *__response) __THROW __nonnull ((1));
892 #endif
895 #ifdef __USE_XOPEN_EXTENDED
896 /* Parse comma separated suboption from *OPTIONP and match against
897 strings in TOKENS. If found return index and set *VALUEP to
898 optional value introduced by an equal sign. If the suboption is
899 not part of TOKENS return in *VALUEP beginning of unknown
900 suboption. On exit *OPTIONP is set to the beginning of the next
901 token or at the terminating NUL character. */
902 extern int getsubopt (char **__restrict __optionp,
903 char *__const *__restrict __tokens,
904 char **__restrict __valuep)
905 __THROW __nonnull ((1, 2, 3));
906 #endif
909 #ifdef __USE_XOPEN
910 /* Setup DES tables according KEY. */
911 extern void setkey (__const char *__key) __THROW __nonnull ((1));
912 #endif
915 /* X/Open pseudo terminal handling. */
917 #ifdef __USE_XOPEN2K
918 /* Return a master pseudo-terminal handle. */
919 extern int posix_openpt (int __oflag);
920 #endif
922 #ifdef __USE_XOPEN
923 /* The next four functions all take a master pseudo-tty fd and
924 perform an operation on the associated slave: */
926 /* Chown the slave to the calling user. */
927 extern int grantpt (int __fd) __THROW;
929 /* Release an internal lock so the slave can be opened.
930 Call after grantpt(). */
931 extern int unlockpt (int __fd) __THROW;
933 /* Return the pathname of the pseudo terminal slave assoicated with
934 the master FD is open on, or NULL on errors.
935 The returned storage is good until the next call to this function. */
936 extern char *ptsname (int __fd) __THROW;
937 #endif
939 #ifdef __USE_GNU
940 /* Store at most BUFLEN characters of the pathname of the slave pseudo
941 terminal associated with the master FD is open on in BUF.
942 Return 0 on success, otherwise an error number. */
943 extern int ptsname_r (int __fd, char *__buf, size_t __buflen)
944 __THROW __nonnull ((2));
946 /* Open a master pseudo terminal and return its file descriptor. */
947 extern int getpt (void);
948 #endif
950 #ifdef __USE_BSD
951 /* Put the 1 minute, 5 minute and 15 minute load averages into the first
952 NELEM elements of LOADAVG. Return the number written (never more than
953 three, but may be less than NELEM), or -1 if an error occurred. */
954 extern int getloadavg (double __loadavg[], int __nelem)
955 __THROW __nonnull ((1));
956 #endif
958 #endif /* don't just need malloc and calloc */
959 #undef __need_malloc_and_calloc
961 __END_DECLS
963 #endif /* stdlib.h */