Update.
[glibc.git] / stdlib / stdlib.h
blobbdf618f1520de19bb5596fe7de4c2b60c1f85514
1 /* Copyright (C) 1991-1999, 2000 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 Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
20 * ISO C Standard: 4.10 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;
138 /* Convert a string to an integer. */
139 extern int atoi (__const char *__nptr) __THROW;
140 /* Convert a string to a long integer. */
141 extern long int atol (__const char *__nptr) __THROW;
143 #if defined __USE_ISOC99 || (defined __GNUC__ && defined __USE_MISC)
144 /* These functions will part of the standard C library in ISO C99. */
145 __extension__ extern long long int atoll (__const char *__nptr) __THROW;
146 #endif
148 /* Convert a string to a floating-point number. */
149 extern double strtod (__const char *__restrict __nptr,
150 char **__restrict __endptr) __THROW;
152 #ifdef __USE_ISOC99
153 /* Likewise for `float' and `long double' sizes of floating-point numbers. */
154 extern float strtof (__const char *__restrict __nptr,
155 char **__restrict __endptr) __THROW;
157 extern long double strtold (__const char *__restrict __nptr,
158 char **__restrict __endptr) __THROW;
159 #endif
161 /* Convert a string to a long integer. */
162 extern long int strtol (__const char *__restrict __nptr,
163 char **__restrict __endptr, int __base) __THROW;
164 /* Convert a string to an unsigned long integer. */
165 extern unsigned long int strtoul (__const char *__restrict __nptr,
166 char **__restrict __endptr, int __base)
167 __THROW;
169 #if defined __GNUC__ && defined __USE_BSD
170 /* Convert a string to a quadword integer. */
171 __extension__
172 extern long long int strtoq (__const char *__restrict __nptr,
173 char **__restrict __endptr, int __base) __THROW;
174 /* Convert a string to an unsigned quadword integer. */
175 __extension__
176 extern unsigned long long int strtouq (__const char *__restrict __nptr,
177 char **__restrict __endptr, int __base)
178 __THROW;
179 #endif /* GCC and use BSD. */
181 #if defined __USE_ISOC99 || (defined __GNUC__ && defined __USE_MISC)
182 /* These functions will part of the standard C library in ISO C99. */
184 /* Convert a string to a quadword integer. */
185 __extension__
186 extern long long int strtoll (__const char *__restrict __nptr,
187 char **__restrict __endptr, int __base) __THROW;
188 /* Convert a string to an unsigned quadword integer. */
189 __extension__
190 extern unsigned long long int strtoull (__const char *__restrict __nptr,
191 char **__restrict __endptr, int __base)
192 __THROW;
193 #endif /* ISO C99 or GCC and use MISC. */
196 #ifdef __USE_GNU
197 /* The concept of one static locale per category is not very well
198 thought out. Many applications will need to process its data using
199 information from several different locales. Another application is
200 the implementation of the internationalization handling in the
201 upcoming ISO C++ standard library. To support this another set of
202 the functions using locale data exist which have an additional
203 argument.
205 Attention: all these functions are *not* standardized in any form.
206 This is a proof-of-concept implementation. */
208 /* Structure for reentrant locale using functions. This is an
209 (almost) opaque type for the user level programs. */
210 # include <xlocale.h>
212 /* Special versions of the functions above which take the locale to
213 use as an additional parameter. */
214 extern long int __strtol_l (__const char *__restrict __nptr,
215 char **__restrict __endptr, int __base,
216 __locale_t __loc) __THROW;
218 extern unsigned long int __strtoul_l (__const char *__restrict __nptr,
219 char **__restrict __endptr,
220 int __base, __locale_t __loc) __THROW;
222 __extension__
223 extern long long int __strtoll_l (__const char *__restrict __nptr,
224 char **__restrict __endptr, int __base,
225 __locale_t __loc) __THROW;
227 __extension__
228 extern unsigned long long int __strtoull_l (__const char *__restrict __nptr,
229 char **__restrict __endptr,
230 int __base, __locale_t __loc)
231 __THROW;
233 extern double __strtod_l (__const char *__restrict __nptr,
234 char **__restrict __endptr, __locale_t __loc)
235 __THROW;
237 extern float __strtof_l (__const char *__restrict __nptr,
238 char **__restrict __endptr, __locale_t __loc) __THROW;
240 extern long double __strtold_l (__const char *__restrict __nptr,
241 char **__restrict __endptr,
242 __locale_t __loc) __THROW;
243 #endif /* GNU */
246 /* The internal entry points for `strtoX' take an extra flag argument
247 saying whether or not to parse locale-dependent number grouping. */
249 extern double __strtod_internal (__const char *__restrict __nptr,
250 char **__restrict __endptr, int __group)
251 __THROW;
252 extern float __strtof_internal (__const char *__restrict __nptr,
253 char **__restrict __endptr, int __group)
254 __THROW;
255 extern long double __strtold_internal (__const char *__restrict __nptr,
256 char **__restrict __endptr,
257 int __group) __THROW;
258 #ifndef __strtol_internal_defined
259 extern long int __strtol_internal (__const char *__restrict __nptr,
260 char **__restrict __endptr,
261 int __base, int __group) __THROW;
262 # define __strtol_internal_defined 1
263 #endif
264 #ifndef __strtoul_internal_defined
265 extern unsigned long int __strtoul_internal (__const char *__restrict __nptr,
266 char **__restrict __endptr,
267 int __base, int __group) __THROW;
268 # define __strtoul_internal_defined 1
269 #endif
270 #if defined __GNUC__ || defined __USE_ISOC99
271 # ifndef __strtoll_internal_defined
272 __extension__
273 extern long long int __strtoll_internal (__const char *__restrict __nptr,
274 char **__restrict __endptr,
275 int __base, int __group) __THROW;
276 # define __strtoll_internal_defined 1
277 # endif
278 # ifndef __strtoull_internal_defined
279 __extension__
280 extern unsigned long long int __strtoull_internal (__const char *
281 __restrict __nptr,
282 char **__restrict __endptr,
283 int __base, int __group)
284 __THROW;
285 # define __strtoull_internal_defined 1
286 # endif
287 #endif /* GCC */
289 #if defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__ \
290 && defined __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;
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 int32_t 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 /* Data structure for communication with thread safe versions. */
477 struct drand48_data
479 unsigned short int x[3]; /* Current state. */
480 unsigned short int a[3]; /* Factor in congruential formula. */
481 unsigned short int c; /* Additive const. in congruential formula. */
482 unsigned short int old_x[3]; /* Old state. */
483 int init; /* Flag for initializing. */
486 # ifdef __USE_MISC
487 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
488 extern int drand48_r (struct drand48_data *__restrict __buffer,
489 double *__restrict __result) __THROW;
490 extern int erand48_r (unsigned short int __xsubi[3],
491 struct drand48_data *__restrict __buffer,
492 double *__restrict __result) __THROW;
494 /* Return non-negative, long integer in [0,2^31). */
495 extern int lrand48_r (struct drand48_data *__restrict __buffer,
496 long int *__restrict __result) __THROW;
497 extern int nrand48_r (unsigned short int __xsubi[3],
498 struct drand48_data *__restrict __buffer,
499 long int *__restrict __result) __THROW;
501 /* Return signed, long integers in [-2^31,2^31). */
502 extern int mrand48_r (struct drand48_data *__restrict __buffer,
503 long int *__restrict __result) __THROW;
504 extern int jrand48_r (unsigned short int __xsubi[3],
505 struct drand48_data *__restrict __buffer,
506 long int *__restrict __result) __THROW;
508 /* Seed random number generator. */
509 extern int srand48_r (long int __seedval, struct drand48_data *__buffer)
510 __THROW;
512 extern int seed48_r (unsigned short int __seed16v[3],
513 struct drand48_data *__buffer) __THROW;
515 extern int lcong48_r (unsigned short int __param[7],
516 struct drand48_data *__buffer) __THROW;
517 # endif /* Use misc. */
518 #endif /* Use SVID or X/Open. */
520 #endif /* don't just need malloc and calloc */
522 #ifndef __malloc_and_calloc_defined
523 #define __malloc_and_calloc_defined
524 /* Allocate SIZE bytes of memory. */
525 extern void *malloc (size_t __size) __THROW __attribute_malloc__;
526 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
527 extern void *calloc (size_t __nmemb, size_t __size)
528 __THROW __attribute_malloc__;
529 #endif
531 #ifndef __need_malloc_and_calloc
532 /* Re-allocate the previously allocated block
533 in PTR, making the new block SIZE bytes long. */
534 extern void *realloc (void *__ptr, size_t __size) __THROW __attribute_malloc__;
535 /* Free a block allocated by `malloc', `realloc' or `calloc'. */
536 extern void free (void *__ptr) __THROW;
538 #ifdef __USE_MISC
539 /* Free a block. An alias for `free'. (Sun Unices). */
540 extern void cfree (void *__ptr) __THROW;
541 #endif /* Use misc. */
543 #if defined __USE_GNU || defined __USE_BSD || defined __USE_MISC
544 # include <alloca.h>
545 #endif /* Use GNU, BSD, or misc. */
547 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
548 /* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */
549 extern void *valloc (size_t __size) __THROW __attribute_malloc__;
550 #endif
552 #ifdef __USE_XOPEN2K
553 /* Allocate memory of SIZE bytes with an alignment of ALIGNMENT. */
554 extern int posix_memalign (void **memptr, size_t alignment, size_t size)
555 __THROW;
556 #endif
558 /* Abort execution and generate a core-dump. */
559 extern void abort (void) __THROW __attribute__ ((__noreturn__));
562 /* Register a function to be called when `exit' is called. */
563 extern int atexit (void (*__func) (void)) __THROW;
565 #ifdef __USE_MISC
566 /* Register a function to be called with the status
567 given to `exit' and the given argument. */
568 extern int __on_exit (void (*__func) (int __status, void *__arg), void *__arg)
569 __THROW;
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 #ifdef __USE_BSD
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 void 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 extern int mkstemp (char *__template) __THROW;
631 #endif
633 #ifdef __USE_BSD
634 /* Create a unique temporary directory from TEMPLATE.
635 The last six characters of TEMPLATE must be "XXXXXX";
636 they are replaced with a string that makes the directory name unique.
637 Returns TEMPLATE, or a null pointer if it cannot get a unique name.
638 The directory is created mode 700. */
639 extern char *mkdtemp (char *__template) __THROW;
640 #endif
643 /* Execute the given line as a shell command. */
644 extern int system (__const char *__command) __THROW;
647 #ifdef __USE_GNU
648 /* Return a malloc'd string containing the canonical absolute name of the
649 named file. The last file name component need not exist, and may be a
650 symlink to a nonexistent file. */
651 extern char *canonicalize_file_name (__const char *__name) __THROW;
652 #endif
654 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
655 /* Return the canonical absolute name of file NAME. The last file name
656 component need not exist, and may be a symlink to a nonexistent file.
657 If RESOLVED is null, the result is malloc'd; otherwise, if the canonical
658 name is PATH_MAX chars or more, returns null with `errno' set to
659 ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, returns the
660 name in RESOLVED. */
661 extern char *realpath (__const char *__restrict __name,
662 char *__restrict __resolved) __THROW;
663 #endif
666 /* Shorthand for type of comparison functions. */
667 #ifndef __COMPAR_FN_T
668 # define __COMPAR_FN_T
669 typedef int (*__compar_fn_t) (__const void *, __const void *);
671 # ifdef __USE_GNU
672 typedef __compar_fn_t comparison_fn_t;
673 # endif
674 #endif
676 /* Do a binary search for KEY in BASE, which consists of NMEMB elements
677 of SIZE bytes each, using COMPAR to perform the comparisons. */
678 extern void *bsearch (__const void *__key, __const void *__base,
679 size_t __nmemb, size_t __size, __compar_fn_t __compar);
681 /* Sort NMEMB elements of BASE, of SIZE bytes each,
682 using COMPAR to perform the comparisons. */
683 extern void qsort (void *__base, size_t __nmemb, size_t __size,
684 __compar_fn_t __compar);
687 /* Return the absolute value of X. */
688 extern int abs (int __x) __THROW __attribute__ ((__const__));
689 extern long int labs (long int __x) __THROW __attribute__ ((__const__));
690 #ifdef __USE_ISOC99
691 __extension__ extern long long int llabs (long long int __x)
692 __THROW __attribute__ ((__const__));
693 #endif
696 /* Return the `div_t', `ldiv_t' or `lldiv_t' representation
697 of the value of NUMER over DENOM. */
698 /* GCC may have built-ins for these someday. */
699 extern div_t div (int __numer, int __denom)
700 __THROW __attribute__ ((__const__));
701 extern ldiv_t ldiv (long int __numer, long int __denom)
702 __THROW __attribute__ ((__const__));
703 #ifdef __USE_ISOC99
704 __extension__ extern lldiv_t lldiv (long long int __numer,
705 long long int __denom)
706 __THROW __attribute__ ((__const__));
707 #endif
710 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED
711 /* Convert floating point numbers to strings. The returned values are
712 valid only until another call to the same function. */
714 /* Convert VALUE to a string with NDIGIT digits and return a pointer to
715 this. Set *DECPT with the position of the decimal character and *SIGN
716 with the sign of the number. */
717 extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt,
718 int *__restrict __sign) __THROW;
720 /* Convert VALUE to a string rounded to NDIGIT decimal digits. Set *DECPT
721 with the position of the decimal character and *SIGN with the sign of
722 the number. */
723 extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt,
724 int *__restrict __sign) __THROW;
726 /* If possible convert VALUE to a string with NDIGIT significant digits.
727 Otherwise use exponential representation. The resulting string will
728 be written to BUF. */
729 extern char *gcvt (double __value, int __ndigit, char *__buf) __THROW;
731 /* Long double versions of above functions. */
732 extern char *qecvt (long double __value, int __ndigit,
733 int *__restrict __decpt, int *__restrict __sign) __THROW;
734 extern char *qfcvt (long double __value, int __ndigit,
735 int *__restrict __decpt, int *__restrict __sign) __THROW;
736 extern char *qgcvt (long double __value, int __ndigit, char *__buf) __THROW;
739 # ifdef __USE_MISC
740 /* Reentrant version of the functions above which provide their own
741 buffers. */
742 extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt,
743 int *__restrict __sign, char *__restrict __buf,
744 size_t __len) __THROW;
745 extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt,
746 int *__restrict __sign, char *__restrict __buf,
747 size_t __len) __THROW;
749 extern int qecvt_r (long double __value, int __ndigit,
750 int *__restrict __decpt, int *__restrict __sign,
751 char *__restrict __buf, size_t __len) __THROW;
752 extern int qfcvt_r (long double __value, int __ndigit,
753 int *__restrict __decpt, int *__restrict __sign,
754 char *__restrict __buf, size_t __len) __THROW;
755 # endif /* misc */
756 #endif /* use MISC || use X/Open Unix */
759 /* Return the length of the multibyte character
760 in S, which is no longer than N. */
761 extern int mblen (__const char *__s, size_t __n) __THROW;
762 /* Return the length of the given multibyte character,
763 putting its `wchar_t' representation in *PWC. */
764 extern int mbtowc (wchar_t *__restrict __pwc,
765 __const char *__restrict __s, size_t __n) __THROW;
766 /* Put the multibyte character represented
767 by WCHAR in S, returning its length. */
768 extern int wctomb (char *__s, wchar_t __wchar) __THROW;
771 /* Convert a multibyte string to a wide char string. */
772 extern size_t mbstowcs (wchar_t *__restrict __pwcs,
773 __const char *__restrict __s, size_t __n) __THROW;
774 /* Convert a wide char string to multibyte string. */
775 extern size_t wcstombs (char *__restrict __s,
776 __const wchar_t *__restrict __pwcs, size_t __n)
777 __THROW;
780 #ifdef __USE_SVID
781 /* Determine whether the string value of RESPONSE matches the affirmation
782 or negative response expression as specified by the LC_MESSAGES category
783 in the program's current locale. Returns 1 if affirmative, 0 if
784 negative, and -1 if not matching. */
785 extern int rpmatch (__const char *__response) __THROW;
786 #endif
789 #ifdef __USE_XOPEN_EXTENDED
790 /* Parse comma separated suboption from *OPTIONP and match against
791 strings in TOKENS. If found return index and set *VALUEP to
792 optional value introduced by an equal sign. If the suboption is
793 not part of TOKENS return in *VALUEP beginning of unknown
794 suboption. On exit *OPTIONP is set to the beginning of the next
795 token or at the terminating NUL character. */
796 extern int getsubopt (char **__restrict __optionp,
797 char *__const *__restrict __tokens,
798 char **__restrict __valuep) __THROW;
799 #endif
802 #ifdef __USE_XOPEN
804 /* Setup DES tables according KEY. */
805 extern void setkey (__const char *__key) __THROW;
807 /* X/Open pseudo terminal handling. */
809 /* The next four functions all take a master pseudo-tty fd and
810 perform an operation on the associated slave: */
812 /* Chown the slave to the calling user. */
813 extern int grantpt (int __fd) __THROW;
815 /* Release an internal lock so the slave can be opened.
816 Call after grantpt(). */
817 extern int unlockpt (int __fd) __THROW;
819 /* Return the pathname of the pseudo terminal slave assoicated with
820 the master FD is open on, or NULL on errors.
821 The returned storage is good until the next call to this function. */
822 extern char *ptsname (int __fd) __THROW;
823 #endif
825 #ifdef __USE_GNU
826 /* Store at most BUFLEN characters of the pathname of the slave pseudo
827 terminal associated with the master FD is open on in BUF.
828 Return 0 on success, otherwise an error number. */
829 extern int ptsname_r (int __fd, char *__buf, size_t __buflen) __THROW;
831 /* Open a master pseudo terminal and return its file descriptor. */
832 extern int getpt (void) __THROW;
833 #endif
835 #ifdef __USE_BSD
836 /* Put the 1 minute, 5 minute and 15 minute load averages into the first
837 NELEM elements of LOADAVG. Return the number written (never more than
838 three, but may be less than NELEM), or -1 if an error occurred. */
839 extern int getloadavg (double __loadavg[], int __nelem) __THROW;
840 #endif
842 #endif /* don't just need malloc and calloc */
843 #undef __need_malloc_and_calloc
845 __END_DECLS
847 #endif /* stdlib.h */