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. */
93 /* Returned by `div'. */
96 int quot
; /* Quotient. */
97 int rem
; /* Remainder. */
100 /* Returned by `ldiv'. */
101 #ifndef __ldiv_t_defined
104 long int quot
; /* Quotient. */
105 long int rem
; /* Remainder. */
107 # define __ldiv_t_defined 1
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. */
117 # define __lldiv_t_defined 1
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__
;
149 /* Convert a string to a floating-point number. */
150 extern double strtod (__const
char *__restrict __nptr
,
151 char **__restrict __endptr
) __THROW
;
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
;
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
)
170 #if defined __GLIBC_HAVE_LONG_LONG && defined __USE_BSD
171 /* Convert a string to a quadword integer. */
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. */
177 extern unsigned long long int strtouq (__const
char *__restrict __nptr
,
178 char **__restrict __endptr
, int __base
)
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. */
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. */
191 extern unsigned long long int strtoull (__const
char *__restrict __nptr
,
192 char **__restrict __endptr
, int __base
)
194 #endif /* ISO C99 or GCC and use MISC. */
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
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
;
218 extern long int strtol_l (__const
char *__restrict __nptr
,
219 char **__restrict __endptr
, int __base
,
220 __locale_t __loc
) __THROW
;
222 extern unsigned long int __strtoul_l (__const
char *__restrict __nptr
,
223 char **__restrict __endptr
,
224 int __base
, __locale_t __loc
) __THROW
;
225 extern unsigned long int strtoul_l (__const
char *__restrict __nptr
,
226 char **__restrict __endptr
,
227 int __base
, __locale_t __loc
) __THROW
;
230 extern long long int __strtoll_l (__const
char *__restrict __nptr
,
231 char **__restrict __endptr
, int __base
,
232 __locale_t __loc
) __THROW
;
234 extern long long int strtoll_l (__const
char *__restrict __nptr
,
235 char **__restrict __endptr
, int __base
,
236 __locale_t __loc
) __THROW
;
239 extern unsigned long long int __strtoull_l (__const
char *__restrict __nptr
,
240 char **__restrict __endptr
,
241 int __base
, __locale_t __loc
)
244 extern unsigned long long int strtoull_l (__const
char *__restrict __nptr
,
245 char **__restrict __endptr
,
246 int __base
, __locale_t __loc
)
249 extern double __strtod_l (__const
char *__restrict __nptr
,
250 char **__restrict __endptr
, __locale_t __loc
)
252 extern double strtod_l (__const
char *__restrict __nptr
,
253 char **__restrict __endptr
, __locale_t __loc
)
256 extern float __strtof_l (__const
char *__restrict __nptr
,
257 char **__restrict __endptr
, __locale_t __loc
) __THROW
;
258 extern float strtof_l (__const
char *__restrict __nptr
,
259 char **__restrict __endptr
, __locale_t __loc
) __THROW
;
261 extern long double __strtold_l (__const
char *__restrict __nptr
,
262 char **__restrict __endptr
,
263 __locale_t __loc
) __THROW
;
264 extern long double strtold_l (__const
char *__restrict __nptr
,
265 char **__restrict __endptr
,
266 __locale_t __loc
) __THROW
;
270 /* The internal entry points for `strtoX' take an extra flag argument
271 saying whether or not to parse locale-dependent number grouping. */
273 extern double __strtod_internal (__const
char *__restrict __nptr
,
274 char **__restrict __endptr
, int __group
)
276 extern float __strtof_internal (__const
char *__restrict __nptr
,
277 char **__restrict __endptr
, int __group
)
279 extern long double __strtold_internal (__const
char *__restrict __nptr
,
280 char **__restrict __endptr
,
281 int __group
) __THROW
;
282 #ifndef __strtol_internal_defined
283 extern long int __strtol_internal (__const
char *__restrict __nptr
,
284 char **__restrict __endptr
,
285 int __base
, int __group
) __THROW
;
286 # define __strtol_internal_defined 1
288 #ifndef __strtoul_internal_defined
289 extern unsigned long int __strtoul_internal (__const
char *__restrict __nptr
,
290 char **__restrict __endptr
,
291 int __base
, int __group
) __THROW
;
292 # define __strtoul_internal_defined 1
294 #if defined __GNUC__ || defined __USE_ISOC99
295 # ifndef __strtoll_internal_defined
297 extern long long int __strtoll_internal (__const
char *__restrict __nptr
,
298 char **__restrict __endptr
,
299 int __base
, int __group
) __THROW
;
300 # define __strtoll_internal_defined 1
302 # ifndef __strtoull_internal_defined
304 extern unsigned long long int __strtoull_internal (__const
char *
306 char **__restrict __endptr
,
307 int __base
, int __group
)
309 # define __strtoull_internal_defined 1
313 #ifdef __USE_EXTERN_INLINES
314 /* Define inline functions which call the internal entry points. */
316 extern __inline
double
317 strtod (__const
char *__restrict __nptr
, char **__restrict __endptr
) __THROW
319 return __strtod_internal (__nptr
, __endptr
, 0);
321 extern __inline
long int
322 strtol (__const
char *__restrict __nptr
, char **__restrict __endptr
,
325 return __strtol_internal (__nptr
, __endptr
, __base
, 0);
327 extern __inline
unsigned long int
328 strtoul (__const
char *__restrict __nptr
, char **__restrict __endptr
,
331 return __strtoul_internal (__nptr
, __endptr
, __base
, 0);
335 extern __inline
float
336 strtof (__const
char *__restrict __nptr
, char **__restrict __endptr
) __THROW
338 return __strtof_internal (__nptr
, __endptr
, 0);
340 extern __inline
long double
341 strtold (__const
char *__restrict __nptr
, char **__restrict __endptr
) __THROW
343 return __strtold_internal (__nptr
, __endptr
, 0);
348 __extension__
extern __inline
long long int
349 strtoq (__const
char *__restrict __nptr
, char **__restrict __endptr
,
352 return __strtoll_internal (__nptr
, __endptr
, __base
, 0);
354 __extension__
extern __inline
unsigned long long int
355 strtouq (__const
char *__restrict __nptr
, char **__restrict __endptr
,
358 return __strtoull_internal (__nptr
, __endptr
, __base
, 0);
362 # if defined __USE_MISC || defined __USE_ISOC99
363 __extension__
extern __inline
long long int
364 strtoll (__const
char *__restrict __nptr
, char **__restrict __endptr
,
367 return __strtoll_internal (__nptr
, __endptr
, __base
, 0);
369 __extension__
extern __inline
unsigned long long int
370 strtoull (__const
char * __restrict __nptr
, char **__restrict __endptr
,
373 return __strtoull_internal (__nptr
, __endptr
, __base
, 0);
377 extern __inline
double
378 atof (__const
char *__nptr
) __THROW
380 return strtod (__nptr
, (char **) NULL
);
383 atoi (__const
char *__nptr
) __THROW
385 return (int) strtol (__nptr
, (char **) NULL
, 10);
387 extern __inline
long int
388 atol (__const
char *__nptr
) __THROW
390 return strtol (__nptr
, (char **) NULL
, 10);
393 # if defined __USE_MISC || defined __USE_ISOC99
394 __extension__
extern __inline
long long int
395 atoll (__const
char *__nptr
) __THROW
397 return strtoll (__nptr
, (char **) NULL
, 10);
400 #endif /* Optimizing and Inlining. */
403 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED
404 /* Convert N to base 64 using the digits "./0-9A-Za-z", least-significant
405 digit first. Returns a pointer to static storage overwritten by the
407 extern char *l64a (long int __n
) __THROW
;
409 /* Read a number from a string S in base 64 as above. */
410 extern long int a64l (__const
char *__s
) __THROW __attribute_pure__
;
413 # include <sys/types.h> /* we need int32_t... */
415 /* These are the functions that actually do things. The `random', `srandom',
416 `initstate' and `setstate' functions are those from BSD Unices.
417 The `rand' and `srand' functions are required by the ANSI standard.
418 We provide both interfaces to the same random number generator. */
419 /* Return a random long integer between 0 and RAND_MAX inclusive. */
420 extern long int random (void) __THROW
;
422 /* Seed the random number generator with the given number. */
423 extern void srandom (unsigned int __seed
) __THROW
;
425 /* Initialize the random number generator to use state buffer STATEBUF,
426 of length STATELEN, and seed it with SEED. Optimal lengths are 8, 16,
427 32, 64, 128 and 256, the bigger the better; values less than 8 will
428 cause an error and values greater than 256 will be rounded down. */
429 extern char *initstate (unsigned int __seed
, char *__statebuf
,
430 size_t __statelen
) __THROW
;
432 /* Switch the random number generator to state buffer STATEBUF,
433 which should have been previously initialized by `initstate'. */
434 extern char *setstate (char *__statebuf
) __THROW
;
438 /* Reentrant versions of the `random' family of functions.
439 These functions all use the following data structure to contain
440 state, rather than global state variables. */
444 int32_t *fptr
; /* Front pointer. */
445 int32_t *rptr
; /* Rear pointer. */
446 int32_t *state
; /* Array of state values. */
447 int rand_type
; /* Type of random number generator. */
448 int rand_deg
; /* Degree of random number generator. */
449 int rand_sep
; /* Distance between front and rear. */
450 int32_t *end_ptr
; /* Pointer behind state table. */
453 extern int random_r (struct random_data
*__restrict __buf
,
454 int32_t *__restrict __result
) __THROW
;
456 extern int srandom_r (unsigned int __seed
, struct random_data
*__buf
) __THROW
;
458 extern int initstate_r (unsigned int __seed
, char *__restrict __statebuf
,
460 struct random_data
*__restrict __buf
) __THROW
;
462 extern int setstate_r (char *__restrict __statebuf
,
463 struct random_data
*__restrict __buf
) __THROW
;
464 # endif /* Use misc. */
465 #endif /* Use SVID || extended X/Open. */
468 /* Return a random integer between 0 and RAND_MAX inclusive. */
469 extern int rand (void) __THROW
;
470 /* Seed the random number generator with the given number. */
471 extern void srand (unsigned int __seed
) __THROW
;
474 /* Reentrant interface according to POSIX.1. */
475 extern int rand_r (unsigned int *__seed
) __THROW
;
479 #if defined __USE_SVID || defined __USE_XOPEN
480 /* System V style 48-bit random number generator functions. */
482 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
483 extern double drand48 (void) __THROW
;
484 extern double erand48 (unsigned short int __xsubi
[3]) __THROW
;
486 /* Return non-negative, long integer in [0,2^31). */
487 extern long int lrand48 (void) __THROW
;
488 extern long int nrand48 (unsigned short int __xsubi
[3]) __THROW
;
490 /* Return signed, long integers in [-2^31,2^31). */
491 extern long int mrand48 (void) __THROW
;
492 extern long int jrand48 (unsigned short int __xsubi
[3]) __THROW
;
494 /* Seed random number generator. */
495 extern void srand48 (long int __seedval
) __THROW
;
496 extern unsigned short int *seed48 (unsigned short int __seed16v
[3]) __THROW
;
497 extern void lcong48 (unsigned short int __param
[7]) __THROW
;
500 /* Data structure for communication with thread safe versions. This
501 type is to be regarded as opaque. It's only exported because users
502 have to allocate objects of this type. */
505 unsigned short int __x
[3]; /* Current state. */
506 unsigned short int __old_x
[3]; /* Old state. */
507 unsigned short int __c
; /* Additive const. in congruential formula. */
508 unsigned short int __init
; /* Flag for initializing. */
509 unsigned long long int __a
; /* Factor in congruential formula. */
512 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
513 extern int drand48_r (struct drand48_data
*__restrict __buffer
,
514 double *__restrict __result
) __THROW
;
515 extern int erand48_r (unsigned short int __xsubi
[3],
516 struct drand48_data
*__restrict __buffer
,
517 double *__restrict __result
) __THROW
;
519 /* Return non-negative, long integer in [0,2^31). */
520 extern int lrand48_r (struct drand48_data
*__restrict __buffer
,
521 long int *__restrict __result
) __THROW
;
522 extern int nrand48_r (unsigned short int __xsubi
[3],
523 struct drand48_data
*__restrict __buffer
,
524 long int *__restrict __result
) __THROW
;
526 /* Return signed, long integers in [-2^31,2^31). */
527 extern int mrand48_r (struct drand48_data
*__restrict __buffer
,
528 long int *__restrict __result
) __THROW
;
529 extern int jrand48_r (unsigned short int __xsubi
[3],
530 struct drand48_data
*__restrict __buffer
,
531 long int *__restrict __result
) __THROW
;
533 /* Seed random number generator. */
534 extern int srand48_r (long int __seedval
, struct drand48_data
*__buffer
)
537 extern int seed48_r (unsigned short int __seed16v
[3],
538 struct drand48_data
*__buffer
) __THROW
;
540 extern int lcong48_r (unsigned short int __param
[7],
541 struct drand48_data
*__buffer
) __THROW
;
542 # endif /* Use misc. */
543 #endif /* Use SVID or X/Open. */
545 #endif /* don't just need malloc and calloc */
547 #ifndef __malloc_and_calloc_defined
548 #define __malloc_and_calloc_defined
549 /* Allocate SIZE bytes of memory. */
550 extern void *malloc (size_t __size
) __THROW __attribute_malloc__
;
551 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
552 extern void *calloc (size_t __nmemb
, size_t __size
)
553 __THROW __attribute_malloc__
;
556 #ifndef __need_malloc_and_calloc
557 /* Re-allocate the previously allocated block
558 in PTR, making the new block SIZE bytes long. */
559 extern void *realloc (void *__ptr
, size_t __size
) __THROW __attribute_malloc__
;
560 /* Free a block allocated by `malloc', `realloc' or `calloc'. */
561 extern void free (void *__ptr
) __THROW
;
564 /* Free a block. An alias for `free'. (Sun Unices). */
565 extern void cfree (void *__ptr
) __THROW
;
566 #endif /* Use misc. */
568 #if defined __USE_GNU || defined __USE_BSD || defined __USE_MISC
570 #endif /* Use GNU, BSD, or misc. */
572 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
573 /* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */
574 extern void *valloc (size_t __size
) __THROW __attribute_malloc__
;
578 /* Allocate memory of SIZE bytes with an alignment of ALIGNMENT. */
579 extern int posix_memalign (void **__memptr
, size_t __alignment
, size_t __size
)
580 __THROW __attribute_malloc__
;
583 /* Abort execution and generate a core-dump. */
584 extern void abort (void) __THROW
__attribute__ ((__noreturn__
));
587 /* Register a function to be called when `exit' is called. */
588 extern int atexit (void (*__func
) (void)) __THROW
;
591 /* Register a function to be called with the status
592 given to `exit' and the given argument. */
593 extern int on_exit (void (*__func
) (int __status
, void *__arg
), void *__arg
)
597 /* Call all functions registered with `atexit' and `on_exit',
598 in the reverse of the order in which they were registered
599 perform stdio cleanup, and terminate program execution with STATUS. */
600 extern void exit (int __status
) __THROW
__attribute__ ((__noreturn__
));
603 /* Terminate the program with STATUS without calling any of the
604 functions registered with `atexit' or `on_exit'. */
605 extern void _Exit (int __status
) __THROW
__attribute__ ((__noreturn__
));
609 /* Return the value of envariable NAME, or NULL if it doesn't exist. */
610 extern char *getenv (__const
char *__name
) __THROW
;
612 /* This function is similar to the above but returns NULL if the
613 programs is running with SUID or SGID enabled. */
614 extern char *__secure_getenv (__const
char *__name
) __THROW
;
616 #if defined __USE_SVID || defined __USE_XOPEN
617 /* The SVID says this is in <stdio.h>, but this seems a better place. */
618 /* Put STRING, which is of the form "NAME=VALUE", in the environment.
619 If there is no `=', remove NAME from the environment. */
620 extern int putenv (char *__string
) __THROW
;
623 #if defined __USE_BSD || defined __USE_XOPEN2K
624 /* Set NAME to VALUE in the environment.
625 If REPLACE is nonzero, overwrite an existing value. */
626 extern int setenv (__const
char *__name
, __const
char *__value
, int __replace
)
629 /* Remove the variable NAME from the environment. */
630 extern int unsetenv (__const
char *__name
) __THROW
;
634 /* The `clearenv' was planned to be added to POSIX.1 but probably
635 never made it. Nevertheless the POSIX.9 standard (POSIX bindings
636 for Fortran 77) requires this function. */
637 extern int clearenv (void) __THROW
;
641 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
642 /* Generate a unique temporary file name from TEMPLATE.
643 The last six characters of TEMPLATE must be "XXXXXX";
644 they are replaced with a string that makes the file name unique.
645 Returns TEMPLATE, or a null pointer if it cannot get a unique file name. */
646 extern char *mktemp (char *__template
) __THROW
;
648 /* Generate a unique temporary file name from TEMPLATE.
649 The last six characters of TEMPLATE must be "XXXXXX";
650 they are replaced with a string that makes the filename unique.
651 Returns a file descriptor open on the file for reading and writing,
652 or -1 if it cannot create a uniquely-named file. */
653 # ifndef __USE_FILE_OFFSET64
654 extern int mkstemp (char *__template
) __THROW
;
657 extern int __REDIRECT (mkstemp
, (char *__template
) __THROW
, mkstemp64
);
659 # define mkstemp mkstemp64
662 # ifdef __USE_LARGEFILE64
663 extern int mkstemp64 (char *__template
) __THROW
;
668 /* Create a unique temporary directory from TEMPLATE.
669 The last six characters of TEMPLATE must be "XXXXXX";
670 they are replaced with a string that makes the directory name unique.
671 Returns TEMPLATE, or a null pointer if it cannot get a unique name.
672 The directory is created mode 700. */
673 extern char *mkdtemp (char *__template
) __THROW
;
677 /* Execute the given line as a shell command. */
678 extern int system (__const
char *__command
) __THROW
;
682 /* Return a malloc'd string containing the canonical absolute name of the
683 named file. The last file name component need not exist, and may be a
684 symlink to a nonexistent file. */
685 extern char *canonicalize_file_name (__const
char *__name
) __THROW
;
688 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
689 /* Return the canonical absolute name of file NAME. The last file name
690 component need not exist, and may be a symlink to a nonexistent file.
691 If RESOLVED is null, the result is malloc'd; otherwise, if the canonical
692 name is PATH_MAX chars or more, returns null with `errno' set to
693 ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, returns the
695 extern char *realpath (__const
char *__restrict __name
,
696 char *__restrict __resolved
) __THROW
;
700 /* Shorthand for type of comparison functions. */
701 #ifndef __COMPAR_FN_T
702 # define __COMPAR_FN_T
703 typedef int (*__compar_fn_t
) (__const
void *, __const
void *);
706 typedef __compar_fn_t comparison_fn_t
;
710 /* Do a binary search for KEY in BASE, which consists of NMEMB elements
711 of SIZE bytes each, using COMPAR to perform the comparisons. */
712 extern void *bsearch (__const
void *__key
, __const
void *__base
,
713 size_t __nmemb
, size_t __size
, __compar_fn_t __compar
);
715 /* Sort NMEMB elements of BASE, of SIZE bytes each,
716 using COMPAR to perform the comparisons. */
717 extern void qsort (void *__base
, size_t __nmemb
, size_t __size
,
718 __compar_fn_t __compar
);
721 /* Return the absolute value of X. */
722 extern int abs (int __x
) __THROW
__attribute__ ((__const__
));
723 extern long int labs (long int __x
) __THROW
__attribute__ ((__const__
));
725 __extension__
extern long long int llabs (long long int __x
)
726 __THROW
__attribute__ ((__const__
));
730 /* Return the `div_t', `ldiv_t' or `lldiv_t' representation
731 of the value of NUMER over DENOM. */
732 /* GCC may have built-ins for these someday. */
733 extern div_t div (int __numer
, int __denom
)
734 __THROW
__attribute__ ((__const__
));
735 extern ldiv_t ldiv (long int __numer
, long int __denom
)
736 __THROW
__attribute__ ((__const__
));
738 __extension__
extern lldiv_t
lldiv (long long int __numer
,
739 long long int __denom
)
740 __THROW
__attribute__ ((__const__
));
744 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED
745 /* Convert floating point numbers to strings. The returned values are
746 valid only until another call to the same function. */
748 /* Convert VALUE to a string with NDIGIT digits and return a pointer to
749 this. Set *DECPT with the position of the decimal character and *SIGN
750 with the sign of the number. */
751 extern char *ecvt (double __value
, int __ndigit
, int *__restrict __decpt
,
752 int *__restrict __sign
) __THROW
;
754 /* Convert VALUE to a string rounded to NDIGIT decimal digits. Set *DECPT
755 with the position of the decimal character and *SIGN with the sign of
757 extern char *fcvt (double __value
, int __ndigit
, int *__restrict __decpt
,
758 int *__restrict __sign
) __THROW
;
760 /* If possible convert VALUE to a string with NDIGIT significant digits.
761 Otherwise use exponential representation. The resulting string will
762 be written to BUF. */
763 extern char *gcvt (double __value
, int __ndigit
, char *__buf
) __THROW
;
767 /* Long double versions of above functions. */
768 extern char *qecvt (long double __value
, int __ndigit
,
769 int *__restrict __decpt
, int *__restrict __sign
) __THROW
;
770 extern char *qfcvt (long double __value
, int __ndigit
,
771 int *__restrict __decpt
, int *__restrict __sign
) __THROW
;
772 extern char *qgcvt (long double __value
, int __ndigit
, char *__buf
) __THROW
;
775 /* Reentrant version of the functions above which provide their own
777 extern int ecvt_r (double __value
, int __ndigit
, int *__restrict __decpt
,
778 int *__restrict __sign
, char *__restrict __buf
,
779 size_t __len
) __THROW
;
780 extern int fcvt_r (double __value
, int __ndigit
, int *__restrict __decpt
,
781 int *__restrict __sign
, char *__restrict __buf
,
782 size_t __len
) __THROW
;
784 extern int qecvt_r (long double __value
, int __ndigit
,
785 int *__restrict __decpt
, int *__restrict __sign
,
786 char *__restrict __buf
, size_t __len
) __THROW
;
787 extern int qfcvt_r (long double __value
, int __ndigit
,
788 int *__restrict __decpt
, int *__restrict __sign
,
789 char *__restrict __buf
, size_t __len
) __THROW
;
791 #endif /* use MISC || use X/Open Unix */
794 /* Return the length of the multibyte character
795 in S, which is no longer than N. */
796 extern int mblen (__const
char *__s
, size_t __n
) __THROW
;
797 /* Return the length of the given multibyte character,
798 putting its `wchar_t' representation in *PWC. */
799 extern int mbtowc (wchar_t *__restrict __pwc
,
800 __const
char *__restrict __s
, size_t __n
) __THROW
;
801 /* Put the multibyte character represented
802 by WCHAR in S, returning its length. */
803 extern int wctomb (char *__s
, wchar_t __wchar
) __THROW
;
806 /* Convert a multibyte string to a wide char string. */
807 extern size_t mbstowcs (wchar_t *__restrict __pwcs
,
808 __const
char *__restrict __s
, size_t __n
) __THROW
;
809 /* Convert a wide char string to multibyte string. */
810 extern size_t wcstombs (char *__restrict __s
,
811 __const
wchar_t *__restrict __pwcs
, size_t __n
)
816 /* Determine whether the string value of RESPONSE matches the affirmation
817 or negative response expression as specified by the LC_MESSAGES category
818 in the program's current locale. Returns 1 if affirmative, 0 if
819 negative, and -1 if not matching. */
820 extern int rpmatch (__const
char *__response
) __THROW
;
824 #ifdef __USE_XOPEN_EXTENDED
825 /* Parse comma separated suboption from *OPTIONP and match against
826 strings in TOKENS. If found return index and set *VALUEP to
827 optional value introduced by an equal sign. If the suboption is
828 not part of TOKENS return in *VALUEP beginning of unknown
829 suboption. On exit *OPTIONP is set to the beginning of the next
830 token or at the terminating NUL character. */
831 extern int getsubopt (char **__restrict __optionp
,
832 char *__const
*__restrict __tokens
,
833 char **__restrict __valuep
) __THROW
;
838 /* Setup DES tables according KEY. */
839 extern void setkey (__const
char *__key
) __THROW
;
843 /* X/Open pseudo terminal handling. */
846 /* Return a master pseudo-terminal handle. */
847 extern int posix_openpt (int __oflag
) __THROW
;
851 /* The next four functions all take a master pseudo-tty fd and
852 perform an operation on the associated slave: */
854 /* Chown the slave to the calling user. */
855 extern int grantpt (int __fd
) __THROW
;
857 /* Release an internal lock so the slave can be opened.
858 Call after grantpt(). */
859 extern int unlockpt (int __fd
) __THROW
;
861 /* Return the pathname of the pseudo terminal slave assoicated with
862 the master FD is open on, or NULL on errors.
863 The returned storage is good until the next call to this function. */
864 extern char *ptsname (int __fd
) __THROW
;
868 /* Store at most BUFLEN characters of the pathname of the slave pseudo
869 terminal associated with the master FD is open on in BUF.
870 Return 0 on success, otherwise an error number. */
871 extern int ptsname_r (int __fd
, char *__buf
, size_t __buflen
) __THROW
;
873 /* Open a master pseudo terminal and return its file descriptor. */
874 extern int getpt (void) __THROW
;
878 /* Put the 1 minute, 5 minute and 15 minute load averages into the first
879 NELEM elements of LOADAVG. Return the number written (never more than
880 three, but may be less than NELEM), or -1 if an error occurred. */
881 extern int getloadavg (double __loadavg
[], int __nelem
) __THROW
;
884 #endif /* don't just need malloc and calloc */
885 #undef __need_malloc_and_calloc
889 #endif /* stdlib.h */