Update.
[glibc.git] / stdlib / stdlib.h
blob1349753b789449f22928aeb76883b66d5df5551f
1 /* Copyright (C) 1991-2002, 2003 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 #endif /* X/Open and <sys/wait.h> not included. */
93 __BEGIN_NAMESPACE_STD
94 /* Returned by `div'. */
95 typedef struct
97 int quot; /* Quotient. */
98 int rem; /* Remainder. */
99 } div_t;
101 /* Returned by `ldiv'. */
102 #ifndef __ldiv_t_defined
103 typedef struct
105 long int quot; /* Quotient. */
106 long int rem; /* Remainder. */
107 } ldiv_t;
108 # define __ldiv_t_defined 1
109 #endif
110 __END_NAMESPACE_STD
112 #if defined __USE_ISOC99 && !defined __lldiv_t_defined
113 __BEGIN_NAMESPACE_C99
114 /* Returned by `lldiv'. */
115 __extension__ typedef struct
117 long long int quot; /* Quotient. */
118 long long int rem; /* Remainder. */
119 } lldiv_t;
120 # define __lldiv_t_defined 1
121 __END_NAMESPACE_C99
122 #endif
125 /* The largest number rand will return (same as INT_MAX). */
126 #define RAND_MAX 2147483647
129 /* We define these the same for all machines.
130 Changes from this to the outside world should be done in `_exit'. */
131 #define EXIT_FAILURE 1 /* Failing exit status. */
132 #define EXIT_SUCCESS 0 /* Successful exit status. */
135 /* Maximum length of a multibyte character in the current locale. */
136 #define MB_CUR_MAX (__ctype_get_mb_cur_max ())
137 extern size_t __ctype_get_mb_cur_max (void) __THROW;
140 __BEGIN_NAMESPACE_STD
141 /* Convert a string to a floating-point number. */
142 extern double atof (__const char *__nptr) __THROW __attribute_pure__;
143 /* Convert a string to an integer. */
144 extern int atoi (__const char *__nptr) __THROW __attribute_pure__;
145 /* Convert a string to a long integer. */
146 extern long int atol (__const char *__nptr) __THROW __attribute_pure__;
147 __END_NAMESPACE_STD
149 #if defined __USE_ISOC99 || (defined __GLIBC_HAVE_LONG_LONG && defined __USE_MISC)
150 __BEGIN_NAMESPACE_C99
151 /* Convert a string to a long long integer. */
152 __extension__ extern long long int atoll (__const char *__nptr)
153 __THROW __attribute_pure__;
154 __END_NAMESPACE_C99
155 #endif
157 __BEGIN_NAMESPACE_STD
158 /* Convert a string to a floating-point number. */
159 extern double strtod (__const char *__restrict __nptr,
160 char **__restrict __endptr) __THROW;
161 __END_NAMESPACE_STD
163 #ifdef __USE_ISOC99
164 __BEGIN_NAMESPACE_C99
165 /* Likewise for `float' and `long double' sizes of floating-point numbers. */
166 extern float strtof (__const char *__restrict __nptr,
167 char **__restrict __endptr) __THROW;
169 extern long double strtold (__const char *__restrict __nptr,
170 char **__restrict __endptr) __THROW;
171 __END_NAMESPACE_C99
172 #endif
174 __BEGIN_NAMESPACE_STD
175 /* Convert a string to a long integer. */
176 extern long int strtol (__const char *__restrict __nptr,
177 char **__restrict __endptr, int __base) __THROW;
178 /* Convert a string to an unsigned long integer. */
179 extern unsigned long int strtoul (__const char *__restrict __nptr,
180 char **__restrict __endptr, int __base)
181 __THROW;
182 __END_NAMESPACE_C99
184 #if defined __GLIBC_HAVE_LONG_LONG && defined __USE_BSD
185 /* Convert a string to a quadword integer. */
186 __extension__
187 extern long long int strtoq (__const char *__restrict __nptr,
188 char **__restrict __endptr, int __base) __THROW;
189 /* Convert a string to an unsigned quadword integer. */
190 __extension__
191 extern unsigned long long int strtouq (__const char *__restrict __nptr,
192 char **__restrict __endptr, int __base)
193 __THROW;
194 #endif /* GCC and use BSD. */
196 #if defined __USE_ISOC99 || (defined __GLIBC_HAVE_LONG_LONG && defined __USE_MISC)
197 __BEGIN_NAMESPACE_C99
198 /* Convert a string to a quadword integer. */
199 __extension__
200 extern long long int strtoll (__const char *__restrict __nptr,
201 char **__restrict __endptr, int __base) __THROW;
202 /* Convert a string to an unsigned quadword integer. */
203 __extension__
204 extern unsigned long long int strtoull (__const char *__restrict __nptr,
205 char **__restrict __endptr, int __base)
206 __THROW;
207 __END_NAMESPACE_C99
208 #endif /* ISO C99 or GCC and use MISC. */
211 #ifdef __USE_GNU
212 /* The concept of one static locale per category is not very well
213 thought out. Many applications will need to process its data using
214 information from several different locales. Another application is
215 the implementation of the internationalization handling in the
216 upcoming ISO C++ standard library. To support this another set of
217 the functions using locale data exist which have an additional
218 argument.
220 Attention: all these functions are *not* standardized in any form.
221 This is a proof-of-concept implementation. */
223 /* Structure for reentrant locale using functions. This is an
224 (almost) opaque type for the user level programs. */
225 # include <xlocale.h>
227 /* Special versions of the functions above which take the locale to
228 use as an additional parameter. */
229 extern long int strtol_l (__const char *__restrict __nptr,
230 char **__restrict __endptr, int __base,
231 __locale_t __loc) __THROW;
233 extern unsigned long int strtoul_l (__const char *__restrict __nptr,
234 char **__restrict __endptr,
235 int __base, __locale_t __loc) __THROW;
237 __extension__
238 extern long long int strtoll_l (__const char *__restrict __nptr,
239 char **__restrict __endptr, int __base,
240 __locale_t __loc) __THROW;
242 __extension__
243 extern unsigned long long int strtoull_l (__const char *__restrict __nptr,
244 char **__restrict __endptr,
245 int __base, __locale_t __loc)
246 __THROW;
248 extern double strtod_l (__const char *__restrict __nptr,
249 char **__restrict __endptr, __locale_t __loc)
250 __THROW;
252 extern float strtof_l (__const char *__restrict __nptr,
253 char **__restrict __endptr, __locale_t __loc) __THROW;
255 extern long double strtold_l (__const char *__restrict __nptr,
256 char **__restrict __endptr,
257 __locale_t __loc) __THROW;
258 #endif /* GNU */
261 /* The internal entry points for `strtoX' take an extra flag argument
262 saying whether or not to parse locale-dependent number grouping. */
264 extern double __strtod_internal (__const char *__restrict __nptr,
265 char **__restrict __endptr, int __group)
266 __THROW;
267 extern float __strtof_internal (__const char *__restrict __nptr,
268 char **__restrict __endptr, int __group)
269 __THROW;
270 extern long double __strtold_internal (__const char *__restrict __nptr,
271 char **__restrict __endptr,
272 int __group) __THROW;
273 #ifndef __strtol_internal_defined
274 extern long int __strtol_internal (__const char *__restrict __nptr,
275 char **__restrict __endptr,
276 int __base, int __group) __THROW;
277 # define __strtol_internal_defined 1
278 #endif
279 #ifndef __strtoul_internal_defined
280 extern unsigned long int __strtoul_internal (__const char *__restrict __nptr,
281 char **__restrict __endptr,
282 int __base, int __group) __THROW;
283 # define __strtoul_internal_defined 1
284 #endif
285 #if defined __GNUC__ || defined __USE_ISOC99
286 # ifndef __strtoll_internal_defined
287 __extension__
288 extern long long int __strtoll_internal (__const char *__restrict __nptr,
289 char **__restrict __endptr,
290 int __base, int __group) __THROW;
291 # define __strtoll_internal_defined 1
292 # endif
293 # ifndef __strtoull_internal_defined
294 __extension__
295 extern unsigned long long int __strtoull_internal (__const char *
296 __restrict __nptr,
297 char **__restrict __endptr,
298 int __base, int __group)
299 __THROW;
300 # define __strtoull_internal_defined 1
301 # endif
302 #endif /* GCC */
304 #ifdef __USE_EXTERN_INLINES
305 /* Define inline functions which call the internal entry points. */
307 __BEGIN_NAMESPACE_STD
308 extern __inline double
309 strtod (__const char *__restrict __nptr, char **__restrict __endptr) __THROW
311 return __strtod_internal (__nptr, __endptr, 0);
313 extern __inline long int
314 strtol (__const char *__restrict __nptr, char **__restrict __endptr,
315 int __base) __THROW
317 return __strtol_internal (__nptr, __endptr, __base, 0);
319 extern __inline unsigned long int
320 strtoul (__const char *__restrict __nptr, char **__restrict __endptr,
321 int __base) __THROW
323 return __strtoul_internal (__nptr, __endptr, __base, 0);
325 __END_NAMESPACE_STD
327 # ifdef __USE_ISOC99
328 __BEGIN_NAMESPACE_C99
329 extern __inline float
330 strtof (__const char *__restrict __nptr, char **__restrict __endptr) __THROW
332 return __strtof_internal (__nptr, __endptr, 0);
334 extern __inline long double
335 strtold (__const char *__restrict __nptr, char **__restrict __endptr) __THROW
337 return __strtold_internal (__nptr, __endptr, 0);
339 __END_NAMESPACE_C99
340 # endif
342 # ifdef __USE_BSD
343 __extension__ extern __inline long long int
344 strtoq (__const char *__restrict __nptr, char **__restrict __endptr,
345 int __base) __THROW
347 return __strtoll_internal (__nptr, __endptr, __base, 0);
349 __extension__ extern __inline unsigned long long int
350 strtouq (__const char *__restrict __nptr, char **__restrict __endptr,
351 int __base) __THROW
353 return __strtoull_internal (__nptr, __endptr, __base, 0);
355 # endif
357 # if defined __USE_MISC || defined __USE_ISOC99
358 __BEGIN_NAMESPACE_C99
359 __extension__ extern __inline long long int
360 strtoll (__const char *__restrict __nptr, char **__restrict __endptr,
361 int __base) __THROW
363 return __strtoll_internal (__nptr, __endptr, __base, 0);
365 __extension__ extern __inline unsigned long long int
366 strtoull (__const char * __restrict __nptr, char **__restrict __endptr,
367 int __base) __THROW
369 return __strtoull_internal (__nptr, __endptr, __base, 0);
371 __END_NAMESPACE_C99
372 # endif
374 __BEGIN_NAMESPACE_STD
375 extern __inline double
376 atof (__const char *__nptr) __THROW
378 return strtod (__nptr, (char **) NULL);
380 extern __inline int
381 atoi (__const char *__nptr) __THROW
383 return (int) strtol (__nptr, (char **) NULL, 10);
385 extern __inline long int
386 atol (__const char *__nptr) __THROW
388 return strtol (__nptr, (char **) NULL, 10);
390 __END_NAMESPACE_STD
392 # if defined __USE_MISC || defined __USE_ISOC99
393 __BEGIN_NAMESPACE_C99
394 __extension__ extern __inline long long int
395 atoll (__const char *__nptr) __THROW
397 return strtoll (__nptr, (char **) NULL, 10);
399 __END_NAMESPACE_C99
400 # endif
401 #endif /* Optimizing and Inlining. */
404 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED
405 /* Convert N to base 64 using the digits "./0-9A-Za-z", least-significant
406 digit first. Returns a pointer to static storage overwritten by the
407 next call. */
408 extern char *l64a (long int __n) __THROW;
410 /* Read a number from a string S in base 64 as above. */
411 extern long int a64l (__const char *__s) __THROW __attribute_pure__;
413 #endif /* Use SVID || extended X/Open. */
415 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED || defined __USE_BSD
416 # include <sys/types.h> /* we need int32_t... */
418 /* These are the functions that actually do things. The `random', `srandom',
419 `initstate' and `setstate' functions are those from BSD Unices.
420 The `rand' and `srand' functions are required by the ANSI standard.
421 We provide both interfaces to the same random number generator. */
422 /* Return a random long integer between 0 and RAND_MAX inclusive. */
423 extern long int random (void) __THROW;
425 /* Seed the random number generator with the given number. */
426 extern void srandom (unsigned int __seed) __THROW;
428 /* Initialize the random number generator to use state buffer STATEBUF,
429 of length STATELEN, and seed it with SEED. Optimal lengths are 8, 16,
430 32, 64, 128 and 256, the bigger the better; values less than 8 will
431 cause an error and values greater than 256 will be rounded down. */
432 extern char *initstate (unsigned int __seed, char *__statebuf,
433 size_t __statelen) __THROW;
435 /* Switch the random number generator to state buffer STATEBUF,
436 which should have been previously initialized by `initstate'. */
437 extern char *setstate (char *__statebuf) __THROW;
440 # ifdef __USE_MISC
441 /* Reentrant versions of the `random' family of functions.
442 These functions all use the following data structure to contain
443 state, rather than global state variables. */
445 struct random_data
447 int32_t *fptr; /* Front pointer. */
448 int32_t *rptr; /* Rear pointer. */
449 int32_t *state; /* Array of state values. */
450 int rand_type; /* Type of random number generator. */
451 int rand_deg; /* Degree of random number generator. */
452 int rand_sep; /* Distance between front and rear. */
453 int32_t *end_ptr; /* Pointer behind state table. */
456 extern int random_r (struct random_data *__restrict __buf,
457 int32_t *__restrict __result) __THROW;
459 extern int srandom_r (unsigned int __seed, struct random_data *__buf) __THROW;
461 extern int initstate_r (unsigned int __seed, char *__restrict __statebuf,
462 size_t __statelen,
463 struct random_data *__restrict __buf) __THROW;
465 extern int setstate_r (char *__restrict __statebuf,
466 struct random_data *__restrict __buf) __THROW;
467 # endif /* Use misc. */
468 #endif /* Use SVID || extended X/Open || BSD. */
471 __BEGIN_NAMESPACE_STD
472 /* Return a random integer between 0 and RAND_MAX inclusive. */
473 extern int rand (void) __THROW;
474 /* Seed the random number generator with the given number. */
475 extern void srand (unsigned int __seed) __THROW;
476 __END_NAMESPACE_STD
478 #ifdef __USE_POSIX
479 /* Reentrant interface according to POSIX.1. */
480 extern int rand_r (unsigned int *__seed) __THROW;
481 #endif
484 #if defined __USE_SVID || defined __USE_XOPEN
485 /* System V style 48-bit random number generator functions. */
487 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
488 extern double drand48 (void) __THROW;
489 extern double erand48 (unsigned short int __xsubi[3]) __THROW;
491 /* Return non-negative, long integer in [0,2^31). */
492 extern long int lrand48 (void) __THROW;
493 extern long int nrand48 (unsigned short int __xsubi[3]) __THROW;
495 /* Return signed, long integers in [-2^31,2^31). */
496 extern long int mrand48 (void) __THROW;
497 extern long int jrand48 (unsigned short int __xsubi[3]) __THROW;
499 /* Seed random number generator. */
500 extern void srand48 (long int __seedval) __THROW;
501 extern unsigned short int *seed48 (unsigned short int __seed16v[3]) __THROW;
502 extern void lcong48 (unsigned short int __param[7]) __THROW;
504 # ifdef __USE_MISC
505 /* Data structure for communication with thread safe versions. This
506 type is to be regarded as opaque. It's only exported because users
507 have to allocate objects of this type. */
508 struct drand48_data
510 unsigned short int __x[3]; /* Current state. */
511 unsigned short int __old_x[3]; /* Old state. */
512 unsigned short int __c; /* Additive const. in congruential formula. */
513 unsigned short int __init; /* Flag for initializing. */
514 unsigned long long int __a; /* Factor in congruential formula. */
517 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
518 extern int drand48_r (struct drand48_data *__restrict __buffer,
519 double *__restrict __result) __THROW;
520 extern int erand48_r (unsigned short int __xsubi[3],
521 struct drand48_data *__restrict __buffer,
522 double *__restrict __result) __THROW;
524 /* Return non-negative, long integer in [0,2^31). */
525 extern int lrand48_r (struct drand48_data *__restrict __buffer,
526 long int *__restrict __result) __THROW;
527 extern int nrand48_r (unsigned short int __xsubi[3],
528 struct drand48_data *__restrict __buffer,
529 long int *__restrict __result) __THROW;
531 /* Return signed, long integers in [-2^31,2^31). */
532 extern int mrand48_r (struct drand48_data *__restrict __buffer,
533 long int *__restrict __result) __THROW;
534 extern int jrand48_r (unsigned short int __xsubi[3],
535 struct drand48_data *__restrict __buffer,
536 long int *__restrict __result) __THROW;
538 /* Seed random number generator. */
539 extern int srand48_r (long int __seedval, struct drand48_data *__buffer)
540 __THROW;
542 extern int seed48_r (unsigned short int __seed16v[3],
543 struct drand48_data *__buffer) __THROW;
545 extern int lcong48_r (unsigned short int __param[7],
546 struct drand48_data *__buffer) __THROW;
547 # endif /* Use misc. */
548 #endif /* Use SVID or X/Open. */
550 #endif /* don't just need malloc and calloc */
552 #ifndef __malloc_and_calloc_defined
553 # define __malloc_and_calloc_defined
554 __BEGIN_NAMESPACE_STD
555 /* Allocate SIZE bytes of memory. */
556 extern void *malloc (size_t __size) __THROW __attribute_malloc__;
557 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
558 extern void *calloc (size_t __nmemb, size_t __size)
559 __THROW __attribute_malloc__;
560 __END_NAMESPACE_STD
561 #endif
563 #ifndef __need_malloc_and_calloc
564 __BEGIN_NAMESPACE_STD
565 /* Re-allocate the previously allocated block
566 in PTR, making the new block SIZE bytes long. */
567 extern void *realloc (void *__ptr, size_t __size) __THROW __attribute_malloc__;
568 /* Free a block allocated by `malloc', `realloc' or `calloc'. */
569 extern void free (void *__ptr) __THROW;
570 __END_NAMESPACE_STD
572 #ifdef __USE_MISC
573 /* Free a block. An alias for `free'. (Sun Unices). */
574 extern void cfree (void *__ptr) __THROW;
575 #endif /* Use misc. */
577 #if defined __USE_GNU || defined __USE_BSD || defined __USE_MISC
578 # include <alloca.h>
579 #endif /* Use GNU, BSD, or misc. */
581 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
582 /* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */
583 extern void *valloc (size_t __size) __THROW __attribute_malloc__;
584 #endif
586 #ifdef __USE_XOPEN2K
587 /* Allocate memory of SIZE bytes with an alignment of ALIGNMENT. */
588 extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size)
589 __THROW __attribute_malloc__;
590 #endif
592 __BEGIN_NAMESPACE_STD
593 /* Abort execution and generate a core-dump. */
594 extern void abort (void) __THROW __attribute__ ((__noreturn__));
597 /* Register a function to be called when `exit' is called. */
598 extern int atexit (void (*__func) (void)) __THROW;
599 __END_NAMESPACE_STD
601 #ifdef __USE_MISC
602 /* Register a function to be called with the status
603 given to `exit' and the given argument. */
604 extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg)
605 __THROW;
606 #endif
608 __BEGIN_NAMESPACE_STD
609 /* Call all functions registered with `atexit' and `on_exit',
610 in the reverse of the order in which they were registered
611 perform stdio cleanup, and terminate program execution with STATUS. */
612 extern void exit (int __status) __THROW __attribute__ ((__noreturn__));
613 __END_NAMESPACE_STD
615 #ifdef __USE_ISOC99
616 __BEGIN_NAMESPACE_C99
617 /* Terminate the program with STATUS without calling any of the
618 functions registered with `atexit' or `on_exit'. */
619 extern void _Exit (int __status) __THROW __attribute__ ((__noreturn__));
620 __END_NAMESPACE_C99
621 #endif
624 __BEGIN_NAMESPACE_STD
625 /* Return the value of envariable NAME, or NULL if it doesn't exist. */
626 extern char *getenv (__const char *__name) __THROW;
627 __END_NAMESPACE_STD
629 /* This function is similar to the above but returns NULL if the
630 programs is running with SUID or SGID enabled. */
631 extern char *__secure_getenv (__const char *__name) __THROW;
633 #if defined __USE_SVID || defined __USE_XOPEN
634 /* The SVID says this is in <stdio.h>, but this seems a better place. */
635 /* Put STRING, which is of the form "NAME=VALUE", in the environment.
636 If there is no `=', remove NAME from the environment. */
637 extern int putenv (char *__string) __THROW;
638 #endif
640 #if defined __USE_BSD || defined __USE_XOPEN2K
641 /* Set NAME to VALUE in the environment.
642 If REPLACE is nonzero, overwrite an existing value. */
643 extern int setenv (__const char *__name, __const char *__value, int __replace)
644 __THROW;
646 /* Remove the variable NAME from the environment. */
647 extern int unsetenv (__const char *__name) __THROW;
648 #endif
650 #ifdef __USE_MISC
651 /* The `clearenv' was planned to be added to POSIX.1 but probably
652 never made it. Nevertheless the POSIX.9 standard (POSIX bindings
653 for Fortran 77) requires this function. */
654 extern int clearenv (void) __THROW;
655 #endif
658 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
659 /* Generate a unique temporary file name from TEMPLATE.
660 The last six characters of TEMPLATE must be "XXXXXX";
661 they are replaced with a string that makes the file name unique.
662 Returns TEMPLATE, or a null pointer if it cannot get a unique file name. */
663 extern char *mktemp (char *__template) __THROW;
665 /* Generate a unique temporary file name from TEMPLATE.
666 The last six characters of TEMPLATE must be "XXXXXX";
667 they are replaced with a string that makes the filename unique.
668 Returns a file descriptor open on the file for reading and writing,
669 or -1 if it cannot create a uniquely-named file.
671 This function is a possible cancellation points and therefore not
672 marked with __THROW. */
673 # ifndef __USE_FILE_OFFSET64
674 extern int mkstemp (char *__template);
675 # else
676 # ifdef __REDIRECT
677 extern int __REDIRECT (mkstemp, (char *__template), mkstemp64);
678 # else
679 # define mkstemp mkstemp64
680 # endif
681 # endif
682 # ifdef __USE_LARGEFILE64
683 extern int mkstemp64 (char *__template);
684 # endif
685 #endif
687 #ifdef __USE_BSD
688 /* Create a unique temporary directory from TEMPLATE.
689 The last six characters of TEMPLATE must be "XXXXXX";
690 they are replaced with a string that makes the directory name unique.
691 Returns TEMPLATE, or a null pointer if it cannot get a unique name.
692 The directory is created mode 700. */
693 extern char *mkdtemp (char *__template) __THROW;
694 #endif
697 __BEGIN_NAMESPACE_STD
698 /* Execute the given line as a shell command.
700 This function is a cancellation point and therefore not marked with
701 __THROW. */
702 extern int system (__const char *__command);
703 __END_NAMESPACE_STD
706 #ifdef __USE_GNU
707 /* Return a malloc'd string containing the canonical absolute name of the
708 named file. The last file name component need not exist, and may be a
709 symlink to a nonexistent file. */
710 extern char *canonicalize_file_name (__const char *__name) __THROW;
711 #endif
713 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
714 /* Return the canonical absolute name of file NAME. The last file name
715 component need not exist, and may be a symlink to a nonexistent file.
716 If RESOLVED is null, the result is malloc'd; otherwise, if the canonical
717 name is PATH_MAX chars or more, returns null with `errno' set to
718 ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, returns the
719 name in RESOLVED. */
720 extern char *realpath (__const char *__restrict __name,
721 char *__restrict __resolved) __THROW;
722 #endif
725 /* Shorthand for type of comparison functions. */
726 #ifndef __COMPAR_FN_T
727 # define __COMPAR_FN_T
728 typedef int (*__compar_fn_t) (__const void *, __const void *);
730 # ifdef __USE_GNU
731 typedef __compar_fn_t comparison_fn_t;
732 # endif
733 #endif
735 __BEGIN_NAMESPACE_STD
736 /* Do a binary search for KEY in BASE, which consists of NMEMB elements
737 of SIZE bytes each, using COMPAR to perform the comparisons. */
738 extern void *bsearch (__const void *__key, __const void *__base,
739 size_t __nmemb, size_t __size, __compar_fn_t __compar);
741 /* Sort NMEMB elements of BASE, of SIZE bytes each,
742 using COMPAR to perform the comparisons. */
743 extern void qsort (void *__base, size_t __nmemb, size_t __size,
744 __compar_fn_t __compar);
747 /* Return the absolute value of X. */
748 extern int abs (int __x) __THROW __attribute__ ((__const__));
749 extern long int labs (long int __x) __THROW __attribute__ ((__const__));
750 __END_NAMESPACE_STD
752 #ifdef __USE_ISOC99
753 __extension__ extern long long int llabs (long long int __x)
754 __THROW __attribute__ ((__const__));
755 #endif
758 __BEGIN_NAMESPACE_STD
759 /* Return the `div_t', `ldiv_t' or `lldiv_t' representation
760 of the value of NUMER over DENOM. */
761 /* GCC may have built-ins for these someday. */
762 extern div_t div (int __numer, int __denom)
763 __THROW __attribute__ ((__const__));
764 extern ldiv_t ldiv (long int __numer, long int __denom)
765 __THROW __attribute__ ((__const__));
766 __END_NAMESPACE_STD
768 #ifdef __USE_ISOC99
769 __BEGIN_NAMESPACE_C99
770 __extension__ extern lldiv_t lldiv (long long int __numer,
771 long long int __denom)
772 __THROW __attribute__ ((__const__));
773 __END_NAMESPACE_C99
774 #endif
777 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED
778 /* Convert floating point numbers to strings. The returned values are
779 valid only until another call to the same function. */
781 /* Convert VALUE to a string with NDIGIT digits and return a pointer to
782 this. Set *DECPT with the position of the decimal character and *SIGN
783 with the sign of the number. */
784 extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt,
785 int *__restrict __sign) __THROW;
787 /* Convert VALUE to a string rounded to NDIGIT decimal digits. Set *DECPT
788 with the position of the decimal character and *SIGN with the sign of
789 the number. */
790 extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt,
791 int *__restrict __sign) __THROW;
793 /* If possible convert VALUE to a string with NDIGIT significant digits.
794 Otherwise use exponential representation. The resulting string will
795 be written to BUF. */
796 extern char *gcvt (double __value, int __ndigit, char *__buf) __THROW;
799 # ifdef __USE_MISC
800 /* Long double versions of above functions. */
801 extern char *qecvt (long double __value, int __ndigit,
802 int *__restrict __decpt, int *__restrict __sign) __THROW;
803 extern char *qfcvt (long double __value, int __ndigit,
804 int *__restrict __decpt, int *__restrict __sign) __THROW;
805 extern char *qgcvt (long double __value, int __ndigit, char *__buf) __THROW;
808 /* Reentrant version of the functions above which provide their own
809 buffers. */
810 extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt,
811 int *__restrict __sign, char *__restrict __buf,
812 size_t __len) __THROW;
813 extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt,
814 int *__restrict __sign, char *__restrict __buf,
815 size_t __len) __THROW;
817 extern int qecvt_r (long double __value, int __ndigit,
818 int *__restrict __decpt, int *__restrict __sign,
819 char *__restrict __buf, size_t __len) __THROW;
820 extern int qfcvt_r (long double __value, int __ndigit,
821 int *__restrict __decpt, int *__restrict __sign,
822 char *__restrict __buf, size_t __len) __THROW;
823 # endif /* misc */
824 #endif /* use MISC || use X/Open Unix */
827 __BEGIN_NAMESPACE_STD
828 /* Return the length of the multibyte character
829 in S, which is no longer than N. */
830 extern int mblen (__const char *__s, size_t __n) __THROW;
831 /* Return the length of the given multibyte character,
832 putting its `wchar_t' representation in *PWC. */
833 extern int mbtowc (wchar_t *__restrict __pwc,
834 __const char *__restrict __s, size_t __n) __THROW;
835 /* Put the multibyte character represented
836 by WCHAR in S, returning its length. */
837 extern int wctomb (char *__s, wchar_t __wchar) __THROW;
840 /* Convert a multibyte string to a wide char string. */
841 extern size_t mbstowcs (wchar_t *__restrict __pwcs,
842 __const char *__restrict __s, size_t __n) __THROW;
843 /* Convert a wide char string to multibyte string. */
844 extern size_t wcstombs (char *__restrict __s,
845 __const wchar_t *__restrict __pwcs, size_t __n)
846 __THROW;
847 __END_NAMESPACE_STD
850 #ifdef __USE_SVID
851 /* Determine whether the string value of RESPONSE matches the affirmation
852 or negative response expression as specified by the LC_MESSAGES category
853 in the program's current locale. Returns 1 if affirmative, 0 if
854 negative, and -1 if not matching. */
855 extern int rpmatch (__const char *__response) __THROW;
856 #endif
859 #ifdef __USE_XOPEN_EXTENDED
860 /* Parse comma separated suboption from *OPTIONP and match against
861 strings in TOKENS. If found return index and set *VALUEP to
862 optional value introduced by an equal sign. If the suboption is
863 not part of TOKENS return in *VALUEP beginning of unknown
864 suboption. On exit *OPTIONP is set to the beginning of the next
865 token or at the terminating NUL character. */
866 extern int getsubopt (char **__restrict __optionp,
867 char *__const *__restrict __tokens,
868 char **__restrict __valuep) __THROW;
869 #endif
872 #ifdef __USE_XOPEN
873 /* Setup DES tables according KEY. */
874 extern void setkey (__const char *__key) __THROW;
875 #endif
878 /* X/Open pseudo terminal handling. */
880 #ifdef __USE_XOPEN2K
881 /* Return a master pseudo-terminal handle. */
882 extern int posix_openpt (int __oflag);
883 #endif
885 #ifdef __USE_XOPEN
886 /* The next four functions all take a master pseudo-tty fd and
887 perform an operation on the associated slave: */
889 /* Chown the slave to the calling user. */
890 extern int grantpt (int __fd) __THROW;
892 /* Release an internal lock so the slave can be opened.
893 Call after grantpt(). */
894 extern int unlockpt (int __fd) __THROW;
896 /* Return the pathname of the pseudo terminal slave assoicated with
897 the master FD is open on, or NULL on errors.
898 The returned storage is good until the next call to this function. */
899 extern char *ptsname (int __fd) __THROW;
900 #endif
902 #ifdef __USE_GNU
903 /* Store at most BUFLEN characters of the pathname of the slave pseudo
904 terminal associated with the master FD is open on in BUF.
905 Return 0 on success, otherwise an error number. */
906 extern int ptsname_r (int __fd, char *__buf, size_t __buflen) __THROW;
908 /* Open a master pseudo terminal and return its file descriptor. */
909 extern int getpt (void);
910 #endif
912 #ifdef __USE_BSD
913 /* Put the 1 minute, 5 minute and 15 minute load averages into the first
914 NELEM elements of LOADAVG. Return the number written (never more than
915 three, but may be less than NELEM), or -1 if an error occurred. */
916 extern int getloadavg (double __loadavg[], int __nelem) __THROW;
917 #endif
919 #endif /* don't just need malloc and calloc */
920 #undef __need_malloc_and_calloc
922 __END_DECLS
924 #endif /* stdlib.h */