1 /* Copyright (C) 1991-99,2000,01,02 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
20 * ISO C99 Standard: 7.20 General utilities <stdlib.h>
27 /* Get size_t, wchar_t and NULL from <stddef.h>. */
29 #ifndef __need_malloc_and_calloc
30 # define __need_wchar_t
37 #ifndef __need_malloc_and_calloc
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>
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; }))
55 # define __WAIT_INT(status) (*(int *) &(status))
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 *
67 /* This works in GCC 2.6.1 and later. */
72 } __WAIT_STATUS
__attribute__ ((__transparent_union__
));
73 # define __WAIT_STATUS_DEFN int *
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. */
94 /* Returned by `div'. */
97 int quot
; /* Quotient. */
98 int rem
; /* Remainder. */
101 /* Returned by `ldiv'. */
102 #ifndef __ldiv_t_defined
105 long int quot
; /* Quotient. */
106 long int rem
; /* Remainder. */
108 # define __ldiv_t_defined 1
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. */
120 # define __lldiv_t_defined 1
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__
;
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__
;
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
;
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
;
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
)
184 #if defined __GLIBC_HAVE_LONG_LONG && defined __USE_BSD
185 /* Convert a string to a quadword integer. */
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. */
191 extern unsigned long long int strtouq (__const
char *__restrict __nptr
,
192 char **__restrict __endptr
, int __base
)
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. */
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. */
204 extern unsigned long long int strtoull (__const
char *__restrict __nptr
,
205 char **__restrict __endptr
, int __base
)
208 #endif /* ISO C99 or GCC and use MISC. */
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
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
;
238 extern long long int strtoll_l (__const
char *__restrict __nptr
,
239 char **__restrict __endptr
, int __base
,
240 __locale_t __loc
) __THROW
;
243 extern unsigned long long int strtoull_l (__const
char *__restrict __nptr
,
244 char **__restrict __endptr
,
245 int __base
, __locale_t __loc
)
248 extern double strtod_l (__const
char *__restrict __nptr
,
249 char **__restrict __endptr
, __locale_t __loc
)
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
;
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
)
267 extern float __strtof_internal (__const
char *__restrict __nptr
,
268 char **__restrict __endptr
, int __group
)
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
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
285 #if defined __GNUC__ || defined __USE_ISOC99
286 # ifndef __strtoll_internal_defined
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
293 # ifndef __strtoull_internal_defined
295 extern unsigned long long int __strtoull_internal (__const
char *
297 char **__restrict __endptr
,
298 int __base
, int __group
)
300 # define __strtoull_internal_defined 1
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
,
317 return __strtol_internal (__nptr
, __endptr
, __base
, 0);
319 extern __inline
unsigned long int
320 strtoul (__const
char *__restrict __nptr
, char **__restrict __endptr
,
323 return __strtoul_internal (__nptr
, __endptr
, __base
, 0);
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);
343 __extension__
extern __inline
long long int
344 strtoq (__const
char *__restrict __nptr
, char **__restrict __endptr
,
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
,
353 return __strtoull_internal (__nptr
, __endptr
, __base
, 0);
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
,
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
,
369 return __strtoull_internal (__nptr
, __endptr
, __base
, 0);
374 __BEGIN_NAMESPACE_STD
375 extern __inline
double
376 atof (__const
char *__nptr
) __THROW
378 return strtod (__nptr
, (char **) NULL
);
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);
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);
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
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__
;
414 # include <sys/types.h> /* we need int32_t... */
416 /* These are the functions that actually do things. The `random', `srandom',
417 `initstate' and `setstate' functions are those from BSD Unices.
418 The `rand' and `srand' functions are required by the ANSI standard.
419 We provide both interfaces to the same random number generator. */
420 /* Return a random long integer between 0 and RAND_MAX inclusive. */
421 extern long int random (void) __THROW
;
423 /* Seed the random number generator with the given number. */
424 extern void srandom (unsigned int __seed
) __THROW
;
426 /* Initialize the random number generator to use state buffer STATEBUF,
427 of length STATELEN, and seed it with SEED. Optimal lengths are 8, 16,
428 32, 64, 128 and 256, the bigger the better; values less than 8 will
429 cause an error and values greater than 256 will be rounded down. */
430 extern char *initstate (unsigned int __seed
, char *__statebuf
,
431 size_t __statelen
) __THROW
;
433 /* Switch the random number generator to state buffer STATEBUF,
434 which should have been previously initialized by `initstate'. */
435 extern char *setstate (char *__statebuf
) __THROW
;
439 /* Reentrant versions of the `random' family of functions.
440 These functions all use the following data structure to contain
441 state, rather than global state variables. */
445 int32_t *fptr
; /* Front pointer. */
446 int32_t *rptr
; /* Rear pointer. */
447 int32_t *state
; /* Array of state values. */
448 int rand_type
; /* Type of random number generator. */
449 int rand_deg
; /* Degree of random number generator. */
450 int rand_sep
; /* Distance between front and rear. */
451 int32_t *end_ptr
; /* Pointer behind state table. */
454 extern int random_r (struct random_data
*__restrict __buf
,
455 int32_t *__restrict __result
) __THROW
;
457 extern int srandom_r (unsigned int __seed
, struct random_data
*__buf
) __THROW
;
459 extern int initstate_r (unsigned int __seed
, char *__restrict __statebuf
,
461 struct random_data
*__restrict __buf
) __THROW
;
463 extern int setstate_r (char *__restrict __statebuf
,
464 struct random_data
*__restrict __buf
) __THROW
;
465 # endif /* Use misc. */
466 #endif /* Use SVID || extended X/Open. */
469 __BEGIN_NAMESPACE_STD
470 /* Return a random integer between 0 and RAND_MAX inclusive. */
471 extern int rand (void) __THROW
;
472 /* Seed the random number generator with the given number. */
473 extern void srand (unsigned int __seed
) __THROW
;
477 /* Reentrant interface according to POSIX.1. */
478 extern int rand_r (unsigned int *__seed
) __THROW
;
482 #if defined __USE_SVID || defined __USE_XOPEN
483 /* System V style 48-bit random number generator functions. */
485 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
486 extern double drand48 (void) __THROW
;
487 extern double erand48 (unsigned short int __xsubi
[3]) __THROW
;
489 /* Return non-negative, long integer in [0,2^31). */
490 extern long int lrand48 (void) __THROW
;
491 extern long int nrand48 (unsigned short int __xsubi
[3]) __THROW
;
493 /* Return signed, long integers in [-2^31,2^31). */
494 extern long int mrand48 (void) __THROW
;
495 extern long int jrand48 (unsigned short int __xsubi
[3]) __THROW
;
497 /* Seed random number generator. */
498 extern void srand48 (long int __seedval
) __THROW
;
499 extern unsigned short int *seed48 (unsigned short int __seed16v
[3]) __THROW
;
500 extern void lcong48 (unsigned short int __param
[7]) __THROW
;
503 /* Data structure for communication with thread safe versions. This
504 type is to be regarded as opaque. It's only exported because users
505 have to allocate objects of this type. */
508 unsigned short int __x
[3]; /* Current state. */
509 unsigned short int __old_x
[3]; /* Old state. */
510 unsigned short int __c
; /* Additive const. in congruential formula. */
511 unsigned short int __init
; /* Flag for initializing. */
512 unsigned long long int __a
; /* Factor in congruential formula. */
515 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
516 extern int drand48_r (struct drand48_data
*__restrict __buffer
,
517 double *__restrict __result
) __THROW
;
518 extern int erand48_r (unsigned short int __xsubi
[3],
519 struct drand48_data
*__restrict __buffer
,
520 double *__restrict __result
) __THROW
;
522 /* Return non-negative, long integer in [0,2^31). */
523 extern int lrand48_r (struct drand48_data
*__restrict __buffer
,
524 long int *__restrict __result
) __THROW
;
525 extern int nrand48_r (unsigned short int __xsubi
[3],
526 struct drand48_data
*__restrict __buffer
,
527 long int *__restrict __result
) __THROW
;
529 /* Return signed, long integers in [-2^31,2^31). */
530 extern int mrand48_r (struct drand48_data
*__restrict __buffer
,
531 long int *__restrict __result
) __THROW
;
532 extern int jrand48_r (unsigned short int __xsubi
[3],
533 struct drand48_data
*__restrict __buffer
,
534 long int *__restrict __result
) __THROW
;
536 /* Seed random number generator. */
537 extern int srand48_r (long int __seedval
, struct drand48_data
*__buffer
)
540 extern int seed48_r (unsigned short int __seed16v
[3],
541 struct drand48_data
*__buffer
) __THROW
;
543 extern int lcong48_r (unsigned short int __param
[7],
544 struct drand48_data
*__buffer
) __THROW
;
545 # endif /* Use misc. */
546 #endif /* Use SVID or X/Open. */
548 #endif /* don't just need malloc and calloc */
550 #ifndef __malloc_and_calloc_defined
551 # define __malloc_and_calloc_defined
552 __BEGIN_NAMESPACE_STD
553 /* Allocate SIZE bytes of memory. */
554 extern void *malloc (size_t __size
) __THROW __attribute_malloc__
;
555 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
556 extern void *calloc (size_t __nmemb
, size_t __size
)
557 __THROW __attribute_malloc__
;
561 #ifndef __need_malloc_and_calloc
562 __BEGIN_NAMESPACE_STD
563 /* Re-allocate the previously allocated block
564 in PTR, making the new block SIZE bytes long. */
565 extern void *realloc (void *__ptr
, size_t __size
) __THROW __attribute_malloc__
;
566 /* Free a block allocated by `malloc', `realloc' or `calloc'. */
567 extern void free (void *__ptr
) __THROW
;
571 /* Free a block. An alias for `free'. (Sun Unices). */
572 extern void cfree (void *__ptr
) __THROW
;
573 #endif /* Use misc. */
575 #if defined __USE_GNU || defined __USE_BSD || defined __USE_MISC
577 #endif /* Use GNU, BSD, or misc. */
579 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
580 /* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */
581 extern void *valloc (size_t __size
) __THROW __attribute_malloc__
;
585 /* Allocate memory of SIZE bytes with an alignment of ALIGNMENT. */
586 extern int posix_memalign (void **__memptr
, size_t __alignment
, size_t __size
)
587 __THROW __attribute_malloc__
;
590 __BEGIN_NAMESPACE_STD
591 /* Abort execution and generate a core-dump. */
592 extern void abort (void) __THROW
__attribute__ ((__noreturn__
));
595 /* Register a function to be called when `exit' is called. */
596 extern int atexit (void (*__func
) (void)) __THROW
;
600 /* Register a function to be called with the status
601 given to `exit' and the given argument. */
602 extern int on_exit (void (*__func
) (int __status
, void *__arg
), void *__arg
)
606 __BEGIN_NAMESPACE_STD
607 /* Call all functions registered with `atexit' and `on_exit',
608 in the reverse of the order in which they were registered
609 perform stdio cleanup, and terminate program execution with STATUS. */
610 extern void exit (int __status
) __THROW
__attribute__ ((__noreturn__
));
614 __BEGIN_NAMESPACE_C99
615 /* Terminate the program with STATUS without calling any of the
616 functions registered with `atexit' or `on_exit'. */
617 extern void _Exit (int __status
) __THROW
__attribute__ ((__noreturn__
));
622 __BEGIN_NAMESPACE_STD
623 /* Return the value of envariable NAME, or NULL if it doesn't exist. */
624 extern char *getenv (__const
char *__name
) __THROW
;
627 /* This function is similar to the above but returns NULL if the
628 programs is running with SUID or SGID enabled. */
629 extern char *__secure_getenv (__const
char *__name
) __THROW
;
631 #if defined __USE_SVID || defined __USE_XOPEN
632 /* The SVID says this is in <stdio.h>, but this seems a better place. */
633 /* Put STRING, which is of the form "NAME=VALUE", in the environment.
634 If there is no `=', remove NAME from the environment. */
635 extern int putenv (char *__string
) __THROW
;
638 #if defined __USE_BSD || defined __USE_XOPEN2K
639 /* Set NAME to VALUE in the environment.
640 If REPLACE is nonzero, overwrite an existing value. */
641 extern int setenv (__const
char *__name
, __const
char *__value
, int __replace
)
644 /* Remove the variable NAME from the environment. */
645 extern int unsetenv (__const
char *__name
) __THROW
;
649 /* The `clearenv' was planned to be added to POSIX.1 but probably
650 never made it. Nevertheless the POSIX.9 standard (POSIX bindings
651 for Fortran 77) requires this function. */
652 extern int clearenv (void) __THROW
;
656 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
657 /* Generate a unique temporary file name from TEMPLATE.
658 The last six characters of TEMPLATE must be "XXXXXX";
659 they are replaced with a string that makes the file name unique.
660 Returns TEMPLATE, or a null pointer if it cannot get a unique file name. */
661 extern char *mktemp (char *__template
) __THROW
;
663 /* Generate a unique temporary file name from TEMPLATE.
664 The last six characters of TEMPLATE must be "XXXXXX";
665 they are replaced with a string that makes the filename unique.
666 Returns a file descriptor open on the file for reading and writing,
667 or -1 if it cannot create a uniquely-named file. */
668 # ifndef __USE_FILE_OFFSET64
669 extern int mkstemp (char *__template
) __THROW
;
672 extern int __REDIRECT (mkstemp
, (char *__template
) __THROW
, mkstemp64
);
674 # define mkstemp mkstemp64
677 # ifdef __USE_LARGEFILE64
678 extern int mkstemp64 (char *__template
) __THROW
;
683 /* Create a unique temporary directory from TEMPLATE.
684 The last six characters of TEMPLATE must be "XXXXXX";
685 they are replaced with a string that makes the directory name unique.
686 Returns TEMPLATE, or a null pointer if it cannot get a unique name.
687 The directory is created mode 700. */
688 extern char *mkdtemp (char *__template
) __THROW
;
692 __BEGIN_NAMESPACE_STD
693 /* Execute the given line as a shell command. */
694 extern int system (__const
char *__command
) __THROW
;
699 /* Return a malloc'd string containing the canonical absolute name of the
700 named file. The last file name component need not exist, and may be a
701 symlink to a nonexistent file. */
702 extern char *canonicalize_file_name (__const
char *__name
) __THROW
;
705 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
706 /* Return the canonical absolute name of file NAME. The last file name
707 component need not exist, and may be a symlink to a nonexistent file.
708 If RESOLVED is null, the result is malloc'd; otherwise, if the canonical
709 name is PATH_MAX chars or more, returns null with `errno' set to
710 ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, returns the
712 extern char *realpath (__const
char *__restrict __name
,
713 char *__restrict __resolved
) __THROW
;
717 /* Shorthand for type of comparison functions. */
718 #ifndef __COMPAR_FN_T
719 # define __COMPAR_FN_T
720 typedef int (*__compar_fn_t
) (__const
void *, __const
void *);
723 typedef __compar_fn_t comparison_fn_t
;
727 __BEGIN_NAMESPACE_STD
728 /* Do a binary search for KEY in BASE, which consists of NMEMB elements
729 of SIZE bytes each, using COMPAR to perform the comparisons. */
730 extern void *bsearch (__const
void *__key
, __const
void *__base
,
731 size_t __nmemb
, size_t __size
, __compar_fn_t __compar
);
733 /* Sort NMEMB elements of BASE, of SIZE bytes each,
734 using COMPAR to perform the comparisons. */
735 extern void qsort (void *__base
, size_t __nmemb
, size_t __size
,
736 __compar_fn_t __compar
);
739 /* Return the absolute value of X. */
740 extern int abs (int __x
) __THROW
__attribute__ ((__const__
));
741 extern long int labs (long int __x
) __THROW
__attribute__ ((__const__
));
745 __extension__
extern long long int llabs (long long int __x
)
746 __THROW
__attribute__ ((__const__
));
750 __BEGIN_NAMESPACE_STD
751 /* Return the `div_t', `ldiv_t' or `lldiv_t' representation
752 of the value of NUMER over DENOM. */
753 /* GCC may have built-ins for these someday. */
754 extern div_t div (int __numer
, int __denom
)
755 __THROW
__attribute__ ((__const__
));
756 extern ldiv_t ldiv (long int __numer
, long int __denom
)
757 __THROW
__attribute__ ((__const__
));
761 __BEGIN_NAMESPACE_C99
762 __extension__
extern lldiv_t
lldiv (long long int __numer
,
763 long long int __denom
)
764 __THROW
__attribute__ ((__const__
));
769 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED
770 /* Convert floating point numbers to strings. The returned values are
771 valid only until another call to the same function. */
773 /* Convert VALUE to a string with NDIGIT digits and return a pointer to
774 this. Set *DECPT with the position of the decimal character and *SIGN
775 with the sign of the number. */
776 extern char *ecvt (double __value
, int __ndigit
, int *__restrict __decpt
,
777 int *__restrict __sign
) __THROW
;
779 /* Convert VALUE to a string rounded to NDIGIT decimal digits. Set *DECPT
780 with the position of the decimal character and *SIGN with the sign of
782 extern char *fcvt (double __value
, int __ndigit
, int *__restrict __decpt
,
783 int *__restrict __sign
) __THROW
;
785 /* If possible convert VALUE to a string with NDIGIT significant digits.
786 Otherwise use exponential representation. The resulting string will
787 be written to BUF. */
788 extern char *gcvt (double __value
, int __ndigit
, char *__buf
) __THROW
;
792 /* Long double versions of above functions. */
793 extern char *qecvt (long double __value
, int __ndigit
,
794 int *__restrict __decpt
, int *__restrict __sign
) __THROW
;
795 extern char *qfcvt (long double __value
, int __ndigit
,
796 int *__restrict __decpt
, int *__restrict __sign
) __THROW
;
797 extern char *qgcvt (long double __value
, int __ndigit
, char *__buf
) __THROW
;
800 /* Reentrant version of the functions above which provide their own
802 extern int ecvt_r (double __value
, int __ndigit
, int *__restrict __decpt
,
803 int *__restrict __sign
, char *__restrict __buf
,
804 size_t __len
) __THROW
;
805 extern int fcvt_r (double __value
, int __ndigit
, int *__restrict __decpt
,
806 int *__restrict __sign
, char *__restrict __buf
,
807 size_t __len
) __THROW
;
809 extern int qecvt_r (long double __value
, int __ndigit
,
810 int *__restrict __decpt
, int *__restrict __sign
,
811 char *__restrict __buf
, size_t __len
) __THROW
;
812 extern int qfcvt_r (long double __value
, int __ndigit
,
813 int *__restrict __decpt
, int *__restrict __sign
,
814 char *__restrict __buf
, size_t __len
) __THROW
;
816 #endif /* use MISC || use X/Open Unix */
819 __BEGIN_NAMESPACE_STD
820 /* Return the length of the multibyte character
821 in S, which is no longer than N. */
822 extern int mblen (__const
char *__s
, size_t __n
) __THROW
;
823 /* Return the length of the given multibyte character,
824 putting its `wchar_t' representation in *PWC. */
825 extern int mbtowc (wchar_t *__restrict __pwc
,
826 __const
char *__restrict __s
, size_t __n
) __THROW
;
827 /* Put the multibyte character represented
828 by WCHAR in S, returning its length. */
829 extern int wctomb (char *__s
, wchar_t __wchar
) __THROW
;
832 /* Convert a multibyte string to a wide char string. */
833 extern size_t mbstowcs (wchar_t *__restrict __pwcs
,
834 __const
char *__restrict __s
, size_t __n
) __THROW
;
835 /* Convert a wide char string to multibyte string. */
836 extern size_t wcstombs (char *__restrict __s
,
837 __const
wchar_t *__restrict __pwcs
, size_t __n
)
843 /* Determine whether the string value of RESPONSE matches the affirmation
844 or negative response expression as specified by the LC_MESSAGES category
845 in the program's current locale. Returns 1 if affirmative, 0 if
846 negative, and -1 if not matching. */
847 extern int rpmatch (__const
char *__response
) __THROW
;
851 #ifdef __USE_XOPEN_EXTENDED
852 /* Parse comma separated suboption from *OPTIONP and match against
853 strings in TOKENS. If found return index and set *VALUEP to
854 optional value introduced by an equal sign. If the suboption is
855 not part of TOKENS return in *VALUEP beginning of unknown
856 suboption. On exit *OPTIONP is set to the beginning of the next
857 token or at the terminating NUL character. */
858 extern int getsubopt (char **__restrict __optionp
,
859 char *__const
*__restrict __tokens
,
860 char **__restrict __valuep
) __THROW
;
865 /* Setup DES tables according KEY. */
866 extern void setkey (__const
char *__key
) __THROW
;
870 /* X/Open pseudo terminal handling. */
873 /* Return a master pseudo-terminal handle. */
874 extern int posix_openpt (int __oflag
) __THROW
;
878 /* The next four functions all take a master pseudo-tty fd and
879 perform an operation on the associated slave: */
881 /* Chown the slave to the calling user. */
882 extern int grantpt (int __fd
) __THROW
;
884 /* Release an internal lock so the slave can be opened.
885 Call after grantpt(). */
886 extern int unlockpt (int __fd
) __THROW
;
888 /* Return the pathname of the pseudo terminal slave assoicated with
889 the master FD is open on, or NULL on errors.
890 The returned storage is good until the next call to this function. */
891 extern char *ptsname (int __fd
) __THROW
;
895 /* Store at most BUFLEN characters of the pathname of the slave pseudo
896 terminal associated with the master FD is open on in BUF.
897 Return 0 on success, otherwise an error number. */
898 extern int ptsname_r (int __fd
, char *__buf
, size_t __buflen
) __THROW
;
900 /* Open a master pseudo terminal and return its file descriptor. */
901 extern int getpt (void) __THROW
;
905 /* Put the 1 minute, 5 minute and 15 minute load averages into the first
906 NELEM elements of LOADAVG. Return the number written (never more than
907 three, but may be less than NELEM), or -1 if an error occurred. */
908 extern int getloadavg (double __loadavg
[], int __nelem
) __THROW
;
911 #endif /* don't just need malloc and calloc */
912 #undef __need_malloc_and_calloc
916 #endif /* stdlib.h */