Update.
[glibc.git] / stdlib / stdlib.h
blob9b0ed9e3a69efa2e29f23afd5075635bfd3df9bf
1 /* Copyright (C) 1991-1999, 2000, 2001 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 /* Returned by `div'. */
94 typedef struct
96 int quot; /* Quotient. */
97 int rem; /* Remainder. */
98 } div_t;
100 /* Returned by `ldiv'. */
101 #ifndef __ldiv_t_defined
102 typedef struct
104 long int quot; /* Quotient. */
105 long int rem; /* Remainder. */
106 } ldiv_t;
107 # define __ldiv_t_defined 1
108 #endif
110 #if defined __USE_ISOC99 && !defined __lldiv_t_defined
111 /* Returned by `lldiv'. */
112 __extension__ typedef struct
114 long long int quot; /* Quotient. */
115 long long int rem; /* Remainder. */
116 } lldiv_t;
117 # define __lldiv_t_defined 1
118 #endif
121 /* The largest number rand will return (same as INT_MAX). */
122 #define RAND_MAX 2147483647
125 /* We define these the same for all machines.
126 Changes from this to the outside world should be done in `_exit'. */
127 #define EXIT_FAILURE 1 /* Failing exit status. */
128 #define EXIT_SUCCESS 0 /* Successful exit status. */
131 /* Maximum length of a multibyte character in the current locale. */
132 #define MB_CUR_MAX (__ctype_get_mb_cur_max ())
133 extern size_t __ctype_get_mb_cur_max (void) __THROW;
136 /* Convert a string to a floating-point number. */
137 extern double atof (__const char *__nptr) __THROW __attribute_pure__;
138 /* Convert a string to an integer. */
139 extern int atoi (__const char *__nptr) __THROW __attribute_pure__;
140 /* Convert a string to a long integer. */
141 extern long int atol (__const char *__nptr) __THROW __attribute_pure__;
143 #if defined __USE_ISOC99 || (defined __GLIBC_HAVE_LONG_LONG && defined __USE_MISC)
144 /* Convert a string to a long long integer. */
145 __extension__ extern long long int atoll (__const char *__nptr)
146 __THROW __attribute_pure__;
147 #endif
149 /* Convert a string to a floating-point number. */
150 extern double strtod (__const char *__restrict __nptr,
151 char **__restrict __endptr) __THROW;
153 #ifdef __USE_ISOC99
154 /* Likewise for `float' and `long double' sizes of floating-point numbers. */
155 extern float strtof (__const char *__restrict __nptr,
156 char **__restrict __endptr) __THROW;
158 extern long double strtold (__const char *__restrict __nptr,
159 char **__restrict __endptr) __THROW;
160 #endif
162 /* Convert a string to a long integer. */
163 extern long int strtol (__const char *__restrict __nptr,
164 char **__restrict __endptr, int __base) __THROW;
165 /* Convert a string to an unsigned long integer. */
166 extern unsigned long int strtoul (__const char *__restrict __nptr,
167 char **__restrict __endptr, int __base)
168 __THROW;
170 #if defined __GLIBC_HAVE_LONG_LONG && defined __USE_BSD
171 /* Convert a string to a quadword integer. */
172 __extension__
173 extern long long int strtoq (__const char *__restrict __nptr,
174 char **__restrict __endptr, int __base) __THROW;
175 /* Convert a string to an unsigned quadword integer. */
176 __extension__
177 extern unsigned long long int strtouq (__const char *__restrict __nptr,
178 char **__restrict __endptr, int __base)
179 __THROW;
180 #endif /* GCC and use BSD. */
182 #if defined __USE_ISOC99 || (defined __GLIBC_HAVE_LONG_LONG && defined __USE_MISC)
183 /* These functions will part of the standard C library in ISO C99. */
185 /* Convert a string to a quadword integer. */
186 __extension__
187 extern long long int strtoll (__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 strtoull (__const char *__restrict __nptr,
192 char **__restrict __endptr, int __base)
193 __THROW;
194 #endif /* ISO C99 or GCC and use MISC. */
197 #ifdef __USE_GNU
198 /* The concept of one static locale per category is not very well
199 thought out. Many applications will need to process its data using
200 information from several different locales. Another application is
201 the implementation of the internationalization handling in the
202 upcoming ISO C++ standard library. To support this another set of
203 the functions using locale data exist which have an additional
204 argument.
206 Attention: all these functions are *not* standardized in any form.
207 This is a proof-of-concept implementation. */
209 /* Structure for reentrant locale using functions. This is an
210 (almost) opaque type for the user level programs. */
211 # include <xlocale.h>
213 /* Special versions of the functions above which take the locale to
214 use as an additional parameter. */
215 extern long int __strtol_l (__const char *__restrict __nptr,
216 char **__restrict __endptr, int __base,
217 __locale_t __loc) __THROW;
219 extern unsigned long int __strtoul_l (__const char *__restrict __nptr,
220 char **__restrict __endptr,
221 int __base, __locale_t __loc) __THROW;
223 __extension__
224 extern long long int __strtoll_l (__const char *__restrict __nptr,
225 char **__restrict __endptr, int __base,
226 __locale_t __loc) __THROW;
228 __extension__
229 extern unsigned long long int __strtoull_l (__const char *__restrict __nptr,
230 char **__restrict __endptr,
231 int __base, __locale_t __loc)
232 __THROW;
234 extern double __strtod_l (__const char *__restrict __nptr,
235 char **__restrict __endptr, __locale_t __loc)
236 __THROW;
238 extern float __strtof_l (__const char *__restrict __nptr,
239 char **__restrict __endptr, __locale_t __loc) __THROW;
241 extern long double __strtold_l (__const char *__restrict __nptr,
242 char **__restrict __endptr,
243 __locale_t __loc) __THROW;
244 #endif /* GNU */
247 /* The internal entry points for `strtoX' take an extra flag argument
248 saying whether or not to parse locale-dependent number grouping. */
250 extern double __strtod_internal (__const char *__restrict __nptr,
251 char **__restrict __endptr, int __group)
252 __THROW;
253 extern float __strtof_internal (__const char *__restrict __nptr,
254 char **__restrict __endptr, int __group)
255 __THROW;
256 extern long double __strtold_internal (__const char *__restrict __nptr,
257 char **__restrict __endptr,
258 int __group) __THROW;
259 #ifndef __strtol_internal_defined
260 extern long int __strtol_internal (__const char *__restrict __nptr,
261 char **__restrict __endptr,
262 int __base, int __group) __THROW;
263 # define __strtol_internal_defined 1
264 #endif
265 #ifndef __strtoul_internal_defined
266 extern unsigned long int __strtoul_internal (__const char *__restrict __nptr,
267 char **__restrict __endptr,
268 int __base, int __group) __THROW;
269 # define __strtoul_internal_defined 1
270 #endif
271 #if defined __GNUC__ || defined __USE_ISOC99
272 # ifndef __strtoll_internal_defined
273 __extension__
274 extern long long int __strtoll_internal (__const char *__restrict __nptr,
275 char **__restrict __endptr,
276 int __base, int __group) __THROW;
277 # define __strtoll_internal_defined 1
278 # endif
279 # ifndef __strtoull_internal_defined
280 __extension__
281 extern unsigned long long int __strtoull_internal (__const char *
282 __restrict __nptr,
283 char **__restrict __endptr,
284 int __base, int __group)
285 __THROW;
286 # define __strtoull_internal_defined 1
287 # endif
288 #endif /* GCC */
290 #ifdef __USE_EXTERN_INLINES
291 /* Define inline functions which call the internal entry points. */
293 extern __inline double
294 strtod (__const char *__restrict __nptr, char **__restrict __endptr) __THROW
296 return __strtod_internal (__nptr, __endptr, 0);
298 extern __inline long int
299 strtol (__const char *__restrict __nptr, char **__restrict __endptr,
300 int __base) __THROW
302 return __strtol_internal (__nptr, __endptr, __base, 0);
304 extern __inline unsigned long int
305 strtoul (__const char *__restrict __nptr, char **__restrict __endptr,
306 int __base) __THROW
308 return __strtoul_internal (__nptr, __endptr, __base, 0);
311 # ifdef __USE_ISOC99
312 extern __inline float
313 strtof (__const char *__restrict __nptr, char **__restrict __endptr) __THROW
315 return __strtof_internal (__nptr, __endptr, 0);
317 extern __inline long double
318 strtold (__const char *__restrict __nptr, char **__restrict __endptr) __THROW
320 return __strtold_internal (__nptr, __endptr, 0);
322 # endif
324 # ifdef __USE_BSD
325 __extension__ extern __inline long long int
326 strtoq (__const char *__restrict __nptr, char **__restrict __endptr,
327 int __base) __THROW
329 return __strtoll_internal (__nptr, __endptr, __base, 0);
331 __extension__ extern __inline unsigned long long int
332 strtouq (__const char *__restrict __nptr, char **__restrict __endptr,
333 int __base) __THROW
335 return __strtoull_internal (__nptr, __endptr, __base, 0);
337 # endif
339 # if defined __USE_MISC || defined __USE_ISOC99
340 __extension__ extern __inline long long int
341 strtoll (__const char *__restrict __nptr, char **__restrict __endptr,
342 int __base) __THROW
344 return __strtoll_internal (__nptr, __endptr, __base, 0);
346 __extension__ extern __inline unsigned long long int
347 strtoull (__const char * __restrict __nptr, char **__restrict __endptr,
348 int __base) __THROW
350 return __strtoull_internal (__nptr, __endptr, __base, 0);
352 # endif
354 extern __inline double
355 atof (__const char *__nptr) __THROW
357 return strtod (__nptr, (char **) NULL);
359 extern __inline int
360 atoi (__const char *__nptr) __THROW
362 return (int) strtol (__nptr, (char **) NULL, 10);
364 extern __inline long int
365 atol (__const char *__nptr) __THROW
367 return strtol (__nptr, (char **) NULL, 10);
370 # if defined __USE_MISC || defined __USE_ISOC99
371 __extension__ extern __inline long long int
372 atoll (__const char *__nptr) __THROW
374 return strtoll (__nptr, (char **) NULL, 10);
376 # endif
377 #endif /* Optimizing and Inlining. */
380 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED
381 /* Convert N to base 64 using the digits "./0-9A-Za-z", least-significant
382 digit first. Returns a pointer to static storage overwritten by the
383 next call. */
384 extern char *l64a (long int __n) __THROW;
386 /* Read a number from a string S in base 64 as above. */
387 extern long int a64l (__const char *__s) __THROW __attribute_pure__;
390 # include <sys/types.h> /* we need int32_t... */
392 /* These are the functions that actually do things. The `random', `srandom',
393 `initstate' and `setstate' functions are those from BSD Unices.
394 The `rand' and `srand' functions are required by the ANSI standard.
395 We provide both interfaces to the same random number generator. */
396 /* Return a random long integer between 0 and RAND_MAX inclusive. */
397 extern long int random (void) __THROW;
399 /* Seed the random number generator with the given number. */
400 extern void srandom (unsigned int __seed) __THROW;
402 /* Initialize the random number generator to use state buffer STATEBUF,
403 of length STATELEN, and seed it with SEED. Optimal lengths are 8, 16,
404 32, 64, 128 and 256, the bigger the better; values less than 8 will
405 cause an error and values greater than 256 will be rounded down. */
406 extern char *initstate (unsigned int __seed, char *__statebuf,
407 size_t __statelen) __THROW;
409 /* Switch the random number generator to state buffer STATEBUF,
410 which should have been previously initialized by `initstate'. */
411 extern char *setstate (char *__statebuf) __THROW;
414 # ifdef __USE_MISC
415 /* Reentrant versions of the `random' family of functions.
416 These functions all use the following data structure to contain
417 state, rather than global state variables. */
419 struct random_data
421 int32_t *fptr; /* Front pointer. */
422 int32_t *rptr; /* Rear pointer. */
423 int32_t *state; /* Array of state values. */
424 int rand_type; /* Type of random number generator. */
425 int rand_deg; /* Degree of random number generator. */
426 int rand_sep; /* Distance between front and rear. */
427 int32_t *end_ptr; /* Pointer behind state table. */
430 extern int random_r (struct random_data *__restrict __buf,
431 int32_t *__restrict __result) __THROW;
433 extern int srandom_r (unsigned int __seed, struct random_data *__buf) __THROW;
435 extern int initstate_r (unsigned int __seed, char *__restrict __statebuf,
436 size_t __statelen,
437 struct random_data *__restrict __buf) __THROW;
439 extern int setstate_r (char *__restrict __statebuf,
440 struct random_data *__restrict __buf) __THROW;
441 # endif /* Use misc. */
442 #endif /* Use SVID || extended X/Open. */
445 /* Return a random integer between 0 and RAND_MAX inclusive. */
446 extern int rand (void) __THROW;
447 /* Seed the random number generator with the given number. */
448 extern void srand (unsigned int __seed) __THROW;
450 #ifdef __USE_POSIX
451 /* Reentrant interface according to POSIX.1. */
452 extern int rand_r (unsigned int *__seed) __THROW;
453 #endif
456 #if defined __USE_SVID || defined __USE_XOPEN
457 /* System V style 48-bit random number generator functions. */
459 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
460 extern double drand48 (void) __THROW;
461 extern double erand48 (unsigned short int __xsubi[3]) __THROW;
463 /* Return non-negative, long integer in [0,2^31). */
464 extern long int lrand48 (void) __THROW;
465 extern long int nrand48 (unsigned short int __xsubi[3]) __THROW;
467 /* Return signed, long integers in [-2^31,2^31). */
468 extern long int mrand48 (void) __THROW;
469 extern long int jrand48 (unsigned short int __xsubi[3]) __THROW;
471 /* Seed random number generator. */
472 extern void srand48 (long int __seedval) __THROW;
473 extern unsigned short int *seed48 (unsigned short int __seed16v[3]) __THROW;
474 extern void lcong48 (unsigned short int __param[7]) __THROW;
476 # ifdef __USE_MISC
477 /* Data structure for communication with thread safe versions. This
478 type is to be regarded as opaque. It's only exported because users
479 have to allocate objects of this type. */
480 struct drand48_data
482 unsigned short int __x[3]; /* Current state. */
483 unsigned short int __old_x[3]; /* Old state. */
484 unsigned short int __c; /* Additive const. in congruential formula. */
485 unsigned short int __init; /* Flag for initializing. */
486 unsigned long long int __a; /* Factor in congruential formula. */
489 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
490 extern int drand48_r (struct drand48_data *__restrict __buffer,
491 double *__restrict __result) __THROW;
492 extern int erand48_r (unsigned short int __xsubi[3],
493 struct drand48_data *__restrict __buffer,
494 double *__restrict __result) __THROW;
496 /* Return non-negative, long integer in [0,2^31). */
497 extern int lrand48_r (struct drand48_data *__restrict __buffer,
498 long int *__restrict __result) __THROW;
499 extern int nrand48_r (unsigned short int __xsubi[3],
500 struct drand48_data *__restrict __buffer,
501 long int *__restrict __result) __THROW;
503 /* Return signed, long integers in [-2^31,2^31). */
504 extern int mrand48_r (struct drand48_data *__restrict __buffer,
505 long int *__restrict __result) __THROW;
506 extern int jrand48_r (unsigned short int __xsubi[3],
507 struct drand48_data *__restrict __buffer,
508 long int *__restrict __result) __THROW;
510 /* Seed random number generator. */
511 extern int srand48_r (long int __seedval, struct drand48_data *__buffer)
512 __THROW;
514 extern int seed48_r (unsigned short int __seed16v[3],
515 struct drand48_data *__buffer) __THROW;
517 extern int lcong48_r (unsigned short int __param[7],
518 struct drand48_data *__buffer) __THROW;
519 # endif /* Use misc. */
520 #endif /* Use SVID or X/Open. */
522 #endif /* don't just need malloc and calloc */
524 #ifndef __malloc_and_calloc_defined
525 #define __malloc_and_calloc_defined
526 /* Allocate SIZE bytes of memory. */
527 extern void *malloc (size_t __size) __THROW __attribute_malloc__;
528 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
529 extern void *calloc (size_t __nmemb, size_t __size)
530 __THROW __attribute_malloc__;
531 #endif
533 #ifndef __need_malloc_and_calloc
534 /* Re-allocate the previously allocated block
535 in PTR, making the new block SIZE bytes long. */
536 extern void *realloc (void *__ptr, size_t __size) __THROW __attribute_malloc__;
537 /* Free a block allocated by `malloc', `realloc' or `calloc'. */
538 extern void free (void *__ptr) __THROW;
540 #ifdef __USE_MISC
541 /* Free a block. An alias for `free'. (Sun Unices). */
542 extern void cfree (void *__ptr) __THROW;
543 #endif /* Use misc. */
545 #if defined __USE_GNU || defined __USE_BSD || defined __USE_MISC
546 # include <alloca.h>
547 #endif /* Use GNU, BSD, or misc. */
549 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
550 /* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */
551 extern void *valloc (size_t __size) __THROW __attribute_malloc__;
552 #endif
554 #ifdef __USE_XOPEN2K
555 /* Allocate memory of SIZE bytes with an alignment of ALIGNMENT. */
556 extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size)
557 __THROW __attribute_malloc__;
558 #endif
560 /* Abort execution and generate a core-dump. */
561 extern void abort (void) __THROW __attribute__ ((__noreturn__));
564 /* Register a function to be called when `exit' is called. */
565 extern int atexit (void (*__func) (void)) __THROW;
567 #ifdef __USE_MISC
568 /* Register a function to be called with the status
569 given to `exit' and the given argument. */
570 extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg)
571 __THROW;
572 #endif
574 /* Call all functions registered with `atexit' and `on_exit',
575 in the reverse of the order in which they were registered
576 perform stdio cleanup, and terminate program execution with STATUS. */
577 extern void exit (int __status) __THROW __attribute__ ((__noreturn__));
579 #ifdef __USE_ISOC99
580 /* Terminate the program with STATUS without calling any of the
581 functions registered with `atexit' or `on_exit'. */
582 extern void _Exit (int __status) __THROW __attribute__ ((__noreturn__));
583 #endif
586 /* Return the value of envariable NAME, or NULL if it doesn't exist. */
587 extern char *getenv (__const char *__name) __THROW;
589 /* This function is similar to the above but returns NULL if the
590 programs is running with SUID or SGID enabled. */
591 extern char *__secure_getenv (__const char *__name) __THROW;
593 #if defined __USE_SVID || defined __USE_XOPEN
594 /* The SVID says this is in <stdio.h>, but this seems a better place. */
595 /* Put STRING, which is of the form "NAME=VALUE", in the environment.
596 If there is no `=', remove NAME from the environment. */
597 extern int putenv (char *__string) __THROW;
598 #endif
600 #if defined __USE_BSD || defined __USE_XOPEN2K
601 /* Set NAME to VALUE in the environment.
602 If REPLACE is nonzero, overwrite an existing value. */
603 extern int setenv (__const char *__name, __const char *__value, int __replace)
604 __THROW;
606 /* Remove the variable NAME from the environment. */
607 extern int unsetenv (__const char *__name) __THROW;
608 #endif
610 #ifdef __USE_MISC
611 /* The `clearenv' was planned to be added to POSIX.1 but probably
612 never made it. Nevertheless the POSIX.9 standard (POSIX bindings
613 for Fortran 77) requires this function. */
614 extern int clearenv (void) __THROW;
615 #endif
618 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
619 /* Generate a unique temporary file name from TEMPLATE.
620 The last six characters of TEMPLATE must be "XXXXXX";
621 they are replaced with a string that makes the file name unique.
622 Returns TEMPLATE, or a null pointer if it cannot get a unique file name. */
623 extern char *mktemp (char *__template) __THROW;
625 /* Generate a unique temporary file name from TEMPLATE.
626 The last six characters of TEMPLATE must be "XXXXXX";
627 they are replaced with a string that makes the filename unique.
628 Returns a file descriptor open on the file for reading and writing,
629 or -1 if it cannot create a uniquely-named file. */
630 # ifndef __USE_FILE_OFFSET64
631 extern int mkstemp (char *__template) __THROW;
632 # else
633 # ifdef __REDIRECT
634 extern int __REDIRECT (mkstemp, (char *__template) __THROW, mkstemp64);
635 # else
636 # define mkstemp mkstemp64
637 # endif
638 # endif
639 # ifdef __USE_LARGEFILE64
640 extern int mkstemp64 (char *__template) __THROW;
641 # endif
642 #endif
644 #ifdef __USE_BSD
645 /* Create a unique temporary directory from TEMPLATE.
646 The last six characters of TEMPLATE must be "XXXXXX";
647 they are replaced with a string that makes the directory name unique.
648 Returns TEMPLATE, or a null pointer if it cannot get a unique name.
649 The directory is created mode 700. */
650 extern char *mkdtemp (char *__template) __THROW;
651 #endif
654 /* Execute the given line as a shell command. */
655 extern int system (__const char *__command) __THROW;
658 #ifdef __USE_GNU
659 /* Return a malloc'd string containing the canonical absolute name of the
660 named file. The last file name component need not exist, and may be a
661 symlink to a nonexistent file. */
662 extern char *canonicalize_file_name (__const char *__name) __THROW;
663 #endif
665 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
666 /* Return the canonical absolute name of file NAME. The last file name
667 component need not exist, and may be a symlink to a nonexistent file.
668 If RESOLVED is null, the result is malloc'd; otherwise, if the canonical
669 name is PATH_MAX chars or more, returns null with `errno' set to
670 ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, returns the
671 name in RESOLVED. */
672 extern char *realpath (__const char *__restrict __name,
673 char *__restrict __resolved) __THROW;
674 #endif
677 /* Shorthand for type of comparison functions. */
678 #ifndef __COMPAR_FN_T
679 # define __COMPAR_FN_T
680 typedef int (*__compar_fn_t) (__const void *, __const void *);
682 # ifdef __USE_GNU
683 typedef __compar_fn_t comparison_fn_t;
684 # endif
685 #endif
687 /* Do a binary search for KEY in BASE, which consists of NMEMB elements
688 of SIZE bytes each, using COMPAR to perform the comparisons. */
689 extern void *bsearch (__const void *__key, __const void *__base,
690 size_t __nmemb, size_t __size, __compar_fn_t __compar);
692 /* Sort NMEMB elements of BASE, of SIZE bytes each,
693 using COMPAR to perform the comparisons. */
694 extern void qsort (void *__base, size_t __nmemb, size_t __size,
695 __compar_fn_t __compar);
698 /* Return the absolute value of X. */
699 extern int abs (int __x) __THROW __attribute__ ((__const__));
700 extern long int labs (long int __x) __THROW __attribute__ ((__const__));
701 #ifdef __USE_ISOC99
702 __extension__ extern long long int llabs (long long int __x)
703 __THROW __attribute__ ((__const__));
704 #endif
707 /* Return the `div_t', `ldiv_t' or `lldiv_t' representation
708 of the value of NUMER over DENOM. */
709 /* GCC may have built-ins for these someday. */
710 extern div_t div (int __numer, int __denom)
711 __THROW __attribute__ ((__const__));
712 extern ldiv_t ldiv (long int __numer, long int __denom)
713 __THROW __attribute__ ((__const__));
714 #ifdef __USE_ISOC99
715 __extension__ extern lldiv_t lldiv (long long int __numer,
716 long long int __denom)
717 __THROW __attribute__ ((__const__));
718 #endif
721 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED
722 /* Convert floating point numbers to strings. The returned values are
723 valid only until another call to the same function. */
725 /* Convert VALUE to a string with NDIGIT digits and return a pointer to
726 this. Set *DECPT with the position of the decimal character and *SIGN
727 with the sign of the number. */
728 extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt,
729 int *__restrict __sign) __THROW;
731 /* Convert VALUE to a string rounded to NDIGIT decimal digits. Set *DECPT
732 with the position of the decimal character and *SIGN with the sign of
733 the number. */
734 extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt,
735 int *__restrict __sign) __THROW;
737 /* If possible convert VALUE to a string with NDIGIT significant digits.
738 Otherwise use exponential representation. The resulting string will
739 be written to BUF. */
740 extern char *gcvt (double __value, int __ndigit, char *__buf) __THROW;
743 # ifdef __USE_MISC
744 /* Long double versions of above functions. */
745 extern char *qecvt (long double __value, int __ndigit,
746 int *__restrict __decpt, int *__restrict __sign) __THROW;
747 extern char *qfcvt (long double __value, int __ndigit,
748 int *__restrict __decpt, int *__restrict __sign) __THROW;
749 extern char *qgcvt (long double __value, int __ndigit, char *__buf) __THROW;
752 /* Reentrant version of the functions above which provide their own
753 buffers. */
754 extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt,
755 int *__restrict __sign, char *__restrict __buf,
756 size_t __len) __THROW;
757 extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt,
758 int *__restrict __sign, char *__restrict __buf,
759 size_t __len) __THROW;
761 extern int qecvt_r (long double __value, int __ndigit,
762 int *__restrict __decpt, int *__restrict __sign,
763 char *__restrict __buf, size_t __len) __THROW;
764 extern int qfcvt_r (long double __value, int __ndigit,
765 int *__restrict __decpt, int *__restrict __sign,
766 char *__restrict __buf, size_t __len) __THROW;
767 # endif /* misc */
768 #endif /* use MISC || use X/Open Unix */
771 /* Return the length of the multibyte character
772 in S, which is no longer than N. */
773 extern int mblen (__const char *__s, size_t __n) __THROW;
774 /* Return the length of the given multibyte character,
775 putting its `wchar_t' representation in *PWC. */
776 extern int mbtowc (wchar_t *__restrict __pwc,
777 __const char *__restrict __s, size_t __n) __THROW;
778 /* Put the multibyte character represented
779 by WCHAR in S, returning its length. */
780 extern int wctomb (char *__s, wchar_t __wchar) __THROW;
783 /* Convert a multibyte string to a wide char string. */
784 extern size_t mbstowcs (wchar_t *__restrict __pwcs,
785 __const char *__restrict __s, size_t __n) __THROW;
786 /* Convert a wide char string to multibyte string. */
787 extern size_t wcstombs (char *__restrict __s,
788 __const wchar_t *__restrict __pwcs, size_t __n)
789 __THROW;
792 #ifdef __USE_SVID
793 /* Determine whether the string value of RESPONSE matches the affirmation
794 or negative response expression as specified by the LC_MESSAGES category
795 in the program's current locale. Returns 1 if affirmative, 0 if
796 negative, and -1 if not matching. */
797 extern int rpmatch (__const char *__response) __THROW;
798 #endif
801 #ifdef __USE_XOPEN_EXTENDED
802 /* Parse comma separated suboption from *OPTIONP and match against
803 strings in TOKENS. If found return index and set *VALUEP to
804 optional value introduced by an equal sign. If the suboption is
805 not part of TOKENS return in *VALUEP beginning of unknown
806 suboption. On exit *OPTIONP is set to the beginning of the next
807 token or at the terminating NUL character. */
808 extern int getsubopt (char **__restrict __optionp,
809 char *__const *__restrict __tokens,
810 char **__restrict __valuep) __THROW;
811 #endif
814 #ifdef __USE_XOPEN
815 /* Setup DES tables according KEY. */
816 extern void setkey (__const char *__key) __THROW;
817 #endif
820 /* X/Open pseudo terminal handling. */
822 #ifdef __USE_XOPEN2K
823 /* Return a master pseudo-terminal handle. */
824 extern int posix_openpt (int __oflag) __THROW;
825 #endif
827 #ifdef __USE_XOPEN
828 /* The next four functions all take a master pseudo-tty fd and
829 perform an operation on the associated slave: */
831 /* Chown the slave to the calling user. */
832 extern int grantpt (int __fd) __THROW;
834 /* Release an internal lock so the slave can be opened.
835 Call after grantpt(). */
836 extern int unlockpt (int __fd) __THROW;
838 /* Return the pathname of the pseudo terminal slave assoicated with
839 the master FD is open on, or NULL on errors.
840 The returned storage is good until the next call to this function. */
841 extern char *ptsname (int __fd) __THROW;
842 #endif
844 #ifdef __USE_GNU
845 /* Store at most BUFLEN characters of the pathname of the slave pseudo
846 terminal associated with the master FD is open on in BUF.
847 Return 0 on success, otherwise an error number. */
848 extern int ptsname_r (int __fd, char *__buf, size_t __buflen) __THROW;
850 /* Open a master pseudo terminal and return its file descriptor. */
851 extern int getpt (void) __THROW;
852 #endif
854 #ifdef __USE_BSD
855 /* Put the 1 minute, 5 minute and 15 minute load averages into the first
856 NELEM elements of LOADAVG. Return the number written (never more than
857 three, but may be less than NELEM), or -1 if an error occurred. */
858 extern int getloadavg (double __loadavg[], int __nelem) __THROW;
859 #endif
861 #endif /* don't just need malloc and calloc */
862 #undef __need_malloc_and_calloc
864 __END_DECLS
866 #endif /* stdlib.h */