1 /* Copyright (C) 1991-2007, 2009 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 # ifdef __UCLIBC_HAS_WCHAR__
31 # define __need_wchar_t
39 #ifndef __need_malloc_and_calloc
42 #if defined __USE_XOPEN && !defined _SYS_WAIT_H
43 /* XPG requires a few symbols from <sys/wait.h> being defined. */
44 # include <bits/waitflags.h>
45 # include <bits/waitstatus.h>
49 /* Lots of hair to allow traditional BSD use of `union wait'
50 as well as POSIX.1 use of `int' for the status word. */
52 # if defined __GNUC__ && !defined __cplusplus
53 # define __WAIT_INT(status) \
54 (__extension__ ({ union { __typeof(status) __in; int __i; } __u; \
55 __u.__in = (status); __u.__i; }))
57 # define __WAIT_INT(status) (*(int *) &(status))
60 /* This is the type of the argument to `wait'. The funky union
61 causes redeclarations with either `int *' or `union wait *' to be
62 allowed without complaint. __WAIT_STATUS_DEFN is the type used in
63 the actual function definitions. */
65 # if !defined __GNUC__ || __GNUC__ < 2 || defined __cplusplus
66 # define __WAIT_STATUS void *
67 # define __WAIT_STATUS_DEFN void *
69 /* This works in GCC 2.6.1 and later. */
74 } __WAIT_STATUS __attribute__ ((__transparent_union__));
75 # define __WAIT_STATUS_DEFN int *
78 # else /* Don't use BSD. */
80 # define __WAIT_INT(status) (status)
81 # define __WAIT_STATUS int *
82 # define __WAIT_STATUS_DEFN int *
84 # endif /* Use BSD. */
86 /* Define the macros <sys/wait.h> also would define this way. */
87 # define WEXITSTATUS(status) __WEXITSTATUS (__WAIT_INT (status))
88 # define WTERMSIG(status) __WTERMSIG (__WAIT_INT (status))
89 # define WSTOPSIG(status) __WSTOPSIG (__WAIT_INT (status))
90 # define WIFEXITED(status) __WIFEXITED (__WAIT_INT (status))
91 # define WIFSIGNALED(status) __WIFSIGNALED (__WAIT_INT (status))
92 # define WIFSTOPPED(status) __WIFSTOPPED (__WAIT_INT (status))
93 # if 0 /* def __WIFCONTINUED */
94 # define WIFCONTINUED(status) __WIFCONTINUED (__WAIT_INT (status))
96 #endif /* X/Open and <sys/wait.h> not included. */
99 /* Returned by `div'. */
102 int quot; /* Quotient. */
103 int rem; /* Remainder. */
106 /* Returned by `ldiv'. */
107 #ifndef __ldiv_t_defined
110 long int quot; /* Quotient. */
111 long int rem; /* Remainder. */
113 # define __ldiv_t_defined 1
117 #if defined __USE_ISOC99 && !defined __lldiv_t_defined
118 __BEGIN_NAMESPACE_C99
119 /* Returned by `lldiv'. */
120 __extension__ typedef struct
122 long long int quot; /* Quotient. */
123 long long int rem; /* Remainder. */
125 # define __lldiv_t_defined 1
130 /* The largest number rand will return (same as INT_MAX). */
131 #define RAND_MAX 2147483647
134 /* We define these the same for all machines.
135 Changes from this to the outside world should be done in `_exit'. */
136 #define EXIT_FAILURE 1 /* Failing exit status. */
137 #define EXIT_SUCCESS 0 /* Successful exit status. */
140 /* Maximum length of a multibyte character in the current locale. */
142 #define MB_CUR_MAX (__ctype_get_mb_cur_max ())
143 extern size_t __ctype_get_mb_cur_max (void) __THROW __wur;
145 #ifdef __UCLIBC_HAS_WCHAR__
146 #define MB_CUR_MAX (_stdlib_mb_cur_max ())
147 extern size_t _stdlib_mb_cur_max (void) __THROW __wur;
148 libc_hidden_proto(_stdlib_mb_cur_max)
152 __BEGIN_NAMESPACE_STD
153 #ifdef __UCLIBC_HAS_FLOATS__
154 /* Convert a string to a floating-point number. */
155 extern double atof (__const char *__nptr)
156 __THROW __attribute_pure__ __nonnull ((1)) __wur;
157 #endif /* __UCLIBC_HAS_FLOATS__ */
158 /* Convert a string to an integer. */
159 extern int atoi (__const char *__nptr)
160 __THROW __attribute_pure__ __nonnull ((1)) __wur;
161 libc_hidden_proto(atoi)
162 /* Convert a string to a long integer. */
163 extern long int atol (__const char *__nptr)
164 __THROW __attribute_pure__ __nonnull ((1)) __wur;
165 libc_hidden_proto(atol)
168 #if defined __USE_ISOC99 || defined __USE_MISC
169 __BEGIN_NAMESPACE_C99
170 /* Convert a string to a long long integer. */
171 __extension__ extern long long int atoll (__const char *__nptr)
172 __THROW __attribute_pure__ __nonnull ((1)) __wur;
176 #ifdef __UCLIBC_HAS_FLOATS__
177 __BEGIN_NAMESPACE_STD
178 /* Convert a string to a floating-point number. */
179 extern double strtod (__const char *__restrict __nptr,
180 char **__restrict __endptr)
181 __THROW __nonnull ((1)) __wur;
182 libc_hidden_proto(strtod)
186 __BEGIN_NAMESPACE_C99
187 /* Likewise for `float' and `long double' sizes of floating-point numbers. */
188 extern float strtof (__const char *__restrict __nptr,
189 char **__restrict __endptr) __THROW __nonnull ((1)) __wur;
191 extern long double strtold (__const char *__restrict __nptr,
192 char **__restrict __endptr)
193 __THROW __nonnull ((1)) __wur;
196 #endif /* __UCLIBC_HAS_FLOATS__ */
198 __BEGIN_NAMESPACE_STD
199 /* Convert a string to a long integer. */
200 extern long int strtol (__const char *__restrict __nptr,
201 char **__restrict __endptr, int __base)
202 __THROW __nonnull ((1)) __wur;
203 libc_hidden_proto(strtol)
204 /* Convert a string to an unsigned long integer. */
205 extern unsigned long int strtoul (__const char *__restrict __nptr,
206 char **__restrict __endptr, int __base)
207 __THROW __nonnull ((1)) __wur;
208 libc_hidden_proto(strtoul)
212 #include <sys/types.h> /* for u_quad_t */
214 /* Convert a string to a quadword integer. */
216 extern long long int strtoq (__const char *__restrict __nptr,
217 char **__restrict __endptr, int __base)
218 __THROW __nonnull ((1)) __wur;
219 /* Convert a string to an unsigned quadword integer. */
221 extern u_quad_t strtouq (__const char *__restrict __nptr,
222 char **__restrict __endptr, int __base)
223 __THROW __nonnull ((1)) __wur;
224 #endif /* GCC and use BSD. */
226 #if defined __USE_ISOC99 || defined __USE_MISC
227 __BEGIN_NAMESPACE_C99
228 /* Convert a string to a quadword integer. */
230 extern long long int strtoll (__const char *__restrict __nptr,
231 char **__restrict __endptr, int __base)
232 __THROW __nonnull ((1)) __wur;
233 libc_hidden_proto(strtoll)
234 /* Convert a string to an unsigned quadword integer. */
236 extern unsigned long long int strtoull (__const char *__restrict __nptr,
237 char **__restrict __endptr, int __base)
238 __THROW __nonnull ((1)) __wur;
240 #endif /* ISO C99 or GCC and use MISC. */
243 #ifdef __UCLIBC_HAS_XLOCALE__
245 /* The concept of one static locale per category is not very well
246 thought out. Many applications will need to process its data using
247 information from several different locales. Another application is
248 the implementation of the internationalization handling in the
249 upcoming ISO C++ standard library. To support this another set of
250 the functions using locale data exist which have an additional
253 Attention: all these functions are *not* standardized in any form.
254 This is a proof-of-concept implementation. */
256 /* Structure for reentrant locale using functions. This is an
257 (almost) opaque type for the user level programs. */
258 # include <xlocale.h>
260 /* Special versions of the functions above which take the locale to
261 use as an additional parameter. */
262 extern long int strtol_l (__const char *__restrict __nptr,
263 char **__restrict __endptr, int __base,
264 __locale_t __loc) __THROW __nonnull ((1, 4)) __wur;
265 libc_hidden_proto(strtol_l)
267 extern unsigned long int strtoul_l (__const char *__restrict __nptr,
268 char **__restrict __endptr,
269 int __base, __locale_t __loc)
270 __THROW __nonnull ((1, 4)) __wur;
271 libc_hidden_proto(strtoul_l)
274 extern long long int strtoll_l (__const char *__restrict __nptr,
275 char **__restrict __endptr, int __base,
277 __THROW __nonnull ((1, 4)) __wur;
280 extern unsigned long long int strtoull_l (__const char *__restrict __nptr,
281 char **__restrict __endptr,
282 int __base, __locale_t __loc)
283 __THROW __nonnull ((1, 4)) __wur;
285 #ifdef __UCLIBC_HAS_FLOATS__
286 extern double strtod_l (__const char *__restrict __nptr,
287 char **__restrict __endptr, __locale_t __loc)
288 __THROW __nonnull ((1, 3)) __wur;
290 extern float strtof_l (__const char *__restrict __nptr,
291 char **__restrict __endptr, __locale_t __loc)
292 __THROW __nonnull ((1, 3)) __wur;
294 extern long double strtold_l (__const char *__restrict __nptr,
295 char **__restrict __endptr,
297 __THROW __nonnull ((1, 3)) __wur;
298 #endif /* __UCLIBC_HAS_FLOATS__ */
301 #endif /* __UCLIBC_HAS_XLOCALE__ */
304 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED
305 /* Convert N to base 64 using the digits "./0-9A-Za-z", least-significant
306 digit first. Returns a pointer to static storage overwritten by the
308 extern char *l64a (long int __n) __THROW __wur;
310 /* Read a number from a string S in base 64 as above. */
311 extern long int a64l (__const char *__s)
312 __THROW __attribute_pure__ __nonnull ((1)) __wur;
314 #endif /* Use SVID || extended X/Open. */
316 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED || defined __USE_BSD
317 # include <sys/types.h> /* we need int32_t... */
319 /* These are the functions that actually do things. The `random', `srandom',
320 `initstate' and `setstate' functions are those from BSD Unices.
321 The `rand' and `srand' functions are required by the ANSI standard.
322 We provide both interfaces to the same random number generator. */
323 /* Return a random long integer between 0 and RAND_MAX inclusive. */
324 extern long int random (void) __THROW;
325 libc_hidden_proto(random)
327 /* Seed the random number generator with the given number. */
328 extern void srandom (unsigned int __seed) __THROW;
330 /* Initialize the random number generator to use state buffer STATEBUF,
331 of length STATELEN, and seed it with SEED. Optimal lengths are 8, 16,
332 32, 64, 128 and 256, the bigger the better; values less than 8 will
333 cause an error and values greater than 256 will be rounded down. */
334 extern char *initstate (unsigned int __seed, char *__statebuf,
335 size_t __statelen) __THROW __nonnull ((2));
337 /* Switch the random number generator to state buffer STATEBUF,
338 which should have been previously initialized by `initstate'. */
339 extern char *setstate (char *__statebuf) __THROW __nonnull ((1));
343 /* Reentrant versions of the `random' family of functions.
344 These functions all use the following data structure to contain
345 state, rather than global state variables. */
349 int32_t *fptr; /* Front pointer. */
350 int32_t *rptr; /* Rear pointer. */
351 int32_t *state; /* Array of state values. */
352 /* random_r.c, TYPE_x, DEG_x, SEP_x - small enough for int8_t */
353 int8_t rand_type; /* Type of random number generator. */
354 int8_t rand_deg; /* Degree of random number generator. */
355 int8_t rand_sep; /* Distance between front and rear. */
356 int32_t *end_ptr; /* Pointer behind state table. */
359 extern int random_r (struct random_data *__restrict __buf,
360 int32_t *__restrict __result) __THROW __nonnull ((1, 2));
361 libc_hidden_proto(random_r)
363 extern int srandom_r (unsigned int __seed, struct random_data *__buf)
364 __THROW __nonnull ((2));
365 libc_hidden_proto(srandom_r)
367 extern int initstate_r (unsigned int __seed, char *__restrict __statebuf,
369 struct random_data *__restrict __buf)
370 __THROW __nonnull ((2, 4));
371 libc_hidden_proto(initstate_r)
373 extern int setstate_r (char *__restrict __statebuf,
374 struct random_data *__restrict __buf)
375 __THROW __nonnull ((1, 2));
376 libc_hidden_proto(setstate_r)
377 # endif /* Use misc. */
378 #endif /* Use SVID || extended X/Open || BSD. */
381 __BEGIN_NAMESPACE_STD
382 /* Return a random integer between 0 and RAND_MAX inclusive. */
383 extern int rand (void) __THROW;
384 /* Seed the random number generator with the given number. */
385 extern void srand (unsigned int __seed) __THROW;
389 /* Reentrant interface according to POSIX.1. */
390 extern int rand_r (unsigned int *__seed) __THROW;
394 #if defined __USE_SVID || defined __USE_XOPEN
395 /* System V style 48-bit random number generator functions. */
397 #ifdef __UCLIBC_HAS_FLOATS__
398 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
399 extern double drand48 (void) __THROW;
400 extern double erand48 (unsigned short int __xsubi[3]) __THROW __nonnull ((1));
401 #endif /* __UCLIBC_HAS_FLOATS__ */
403 /* Return non-negative, long integer in [0,2^31). */
404 extern long int lrand48 (void) __THROW;
405 extern long int nrand48 (unsigned short int __xsubi[3])
406 __THROW __nonnull ((1));
408 /* Return signed, long integers in [-2^31,2^31). */
409 extern long int mrand48 (void) __THROW;
410 extern long int jrand48 (unsigned short int __xsubi[3])
411 __THROW __nonnull ((1));
413 /* Seed random number generator. */
414 extern void srand48 (long int __seedval) __THROW;
415 extern unsigned short int *seed48 (unsigned short int __seed16v[3])
416 __THROW __nonnull ((1));
417 extern void lcong48 (unsigned short int __param[7]) __THROW __nonnull ((1));
420 /* Data structure for communication with thread safe versions. This
421 type is to be regarded as opaque. It's only exported because users
422 have to allocate objects of this type. */
425 unsigned short int __x[3]; /* Current state. */
426 unsigned short int __old_x[3]; /* Old state. */
427 unsigned short int __c; /* Additive const. in congruential formula. */
428 unsigned short int __init; /* Flag for initializing. */
429 unsigned long long int __a; /* Factor in congruential formula. */
432 #ifdef __UCLIBC_HAS_FLOATS__
433 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
434 extern int drand48_r (struct drand48_data *__restrict __buffer,
435 double *__restrict __result) __THROW __nonnull ((1, 2));
436 extern int erand48_r (unsigned short int __xsubi[3],
437 struct drand48_data *__restrict __buffer,
438 double *__restrict __result) __THROW __nonnull ((1, 2));
439 libc_hidden_proto(erand48_r)
440 #endif /* __UCLIBC_HAS_FLOATS__ */
442 /* Return non-negative, long integer in [0,2^31). */
443 extern int lrand48_r (struct drand48_data *__restrict __buffer,
444 long int *__restrict __result)
445 __THROW __nonnull ((1, 2));
446 libc_hidden_proto(lrand48_r)
447 extern int nrand48_r (unsigned short int __xsubi[3],
448 struct drand48_data *__restrict __buffer,
449 long int *__restrict __result)
450 __THROW __nonnull ((1, 2));
451 libc_hidden_proto(nrand48_r)
453 /* Return signed, long integers in [-2^31,2^31). */
454 extern int mrand48_r (struct drand48_data *__restrict __buffer,
455 long int *__restrict __result)
456 __THROW __nonnull ((1, 2));
457 extern int jrand48_r (unsigned short int __xsubi[3],
458 struct drand48_data *__restrict __buffer,
459 long int *__restrict __result)
460 __THROW __nonnull ((1, 2));
461 libc_hidden_proto(jrand48_r)
463 /* Seed random number generator. */
464 extern int srand48_r (long int __seedval, struct drand48_data *__buffer)
465 __THROW __nonnull ((2));
466 libc_hidden_proto(srand48_r)
468 extern int seed48_r (unsigned short int __seed16v[3],
469 struct drand48_data *__buffer) __THROW __nonnull ((1, 2));
470 libc_hidden_proto(seed48_r)
472 extern int lcong48_r (unsigned short int __param[7],
473 struct drand48_data *__buffer)
474 __THROW __nonnull ((1, 2));
475 # endif /* Use misc. */
476 #endif /* Use SVID or X/Open. */
478 #endif /* don't just need malloc and calloc */
480 #ifndef __malloc_and_calloc_defined
481 # define __malloc_and_calloc_defined
482 __BEGIN_NAMESPACE_STD
483 /* Allocate SIZE bytes of memory. */
484 extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
485 /* We want the malloc symbols overridable at runtime
486 * libc_hidden_proto(malloc) */
487 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
488 extern void *calloc (size_t __nmemb, size_t __size)
489 __THROW __attribute_malloc__ __wur;
493 #ifndef __need_malloc_and_calloc
494 __BEGIN_NAMESPACE_STD
495 /* Re-allocate the previously allocated block
496 in PTR, making the new block SIZE bytes long. */
497 extern void *realloc (void *__ptr, size_t __size)
498 __THROW __attribute_malloc__ __attribute_warn_unused_result__;
499 /* Free a block allocated by `malloc', `realloc' or `calloc'. */
500 extern void free (void *__ptr) __THROW;
504 /* Free a block. An alias for `free'. (Sun Unices). */
505 extern void cfree (void *__ptr) __THROW;
506 #endif /* Use misc. */
508 #if defined __USE_GNU || defined __USE_BSD || defined __USE_MISC
510 #endif /* Use GNU, BSD, or misc. */
512 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
513 /* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */
514 extern void *valloc (size_t __size) __THROW __attribute_malloc__ __wur;
517 #if defined __USE_XOPEN2K && defined __UCLIBC_HAS_ADVANCED_REALTIME__
518 /* Allocate memory of SIZE bytes with an alignment of ALIGNMENT. */
519 extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size)
520 __THROW __nonnull ((1)) __wur;
523 __BEGIN_NAMESPACE_STD
524 /* Abort execution and generate a core-dump. */
525 extern void abort (void) __THROW __attribute__ ((__noreturn__));
526 libc_hidden_proto(abort)
529 /* Register a function to be called when `exit' is called. */
530 extern int atexit (void (*__func) (void)) __THROW __nonnull ((1));
534 /* Register a function to be called with the status
535 given to `exit' and the given argument. */
536 extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg)
537 __THROW __nonnull ((1));
540 __BEGIN_NAMESPACE_STD
541 /* Call all functions registered with `atexit' and `on_exit',
542 in the reverse of the order in which they were registered
543 perform stdio cleanup, and terminate program execution with STATUS. */
544 extern void exit (int __status) __THROW __attribute__ ((__noreturn__));
545 libc_hidden_proto(exit)
549 __BEGIN_NAMESPACE_C99
550 /* Terminate the program with STATUS without calling any of the
551 functions registered with `atexit' or `on_exit'. */
552 extern void _Exit (int __status) __THROW __attribute__ ((__noreturn__));
557 __BEGIN_NAMESPACE_STD
558 /* Return the value of envariable NAME, or NULL if it doesn't exist. */
559 extern char *getenv (__const char *__name) __THROW __nonnull ((1)) __wur;
560 libc_hidden_proto(getenv)
563 /* This function is similar to the above but returns NULL if the
564 programs is running with SUID or SGID enabled. */
565 extern char *__secure_getenv (__const char *__name)
566 __THROW __nonnull ((1)) __wur;
568 #if defined __USE_SVID || defined __USE_XOPEN
569 /* The SVID says this is in <stdio.h>, but this seems a better place. */
570 /* Put STRING, which is of the form "NAME=VALUE", in the environment.
571 If there is no `=', remove NAME from the environment. */
572 extern int putenv (char *__string) __THROW __nonnull ((1));
575 #if defined __USE_BSD || defined __USE_XOPEN2K
576 /* Set NAME to VALUE in the environment.
577 If REPLACE is nonzero, overwrite an existing value. */
578 extern int setenv (__const char *__name, __const char *__value, int __replace)
579 __THROW __nonnull ((2));
580 libc_hidden_proto(setenv)
582 /* Remove the variable NAME from the environment. */
583 extern int unsetenv (__const char *__name) __THROW;
584 libc_hidden_proto(unsetenv)
587 /* The following is used by uClibc in atexit.c and sysconf.c */
588 /* We have no limit when __UCLIBC_DYNAMIC_ATEXIT__ is enabled. */
589 #ifdef __UCLIBC_DYNAMIC_ATEXIT__
590 # define __UCLIBC_MAX_ATEXIT INT_MAX
592 # define __UCLIBC_MAX_ATEXIT 20
597 /* The `clearenv' was planned to be added to POSIX.1 but probably
598 never made it. Nevertheless the POSIX.9 standard (POSIX bindings
599 for Fortran 77) requires this function. */
600 extern int clearenv (void) __THROW;
604 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
605 # if defined __UCLIBC_SUSV3_LEGACY__
606 /* Generate a unique temporary file name from TEMPLATE.
607 The last six characters of TEMPLATE must be "XXXXXX";
608 they are replaced with a string that makes the file name unique.
609 Returns TEMPLATE, or a null pointer if it cannot get a unique file name. */
610 extern char *mktemp (char *__template) __THROW __nonnull ((1)) __wur;
613 /* Generate a unique temporary file name from TEMPLATE.
614 The last six characters of TEMPLATE must be "XXXXXX";
615 they are replaced with a string that makes the filename unique.
616 Returns a file descriptor open on the file for reading and writing,
617 or -1 if it cannot create a uniquely-named file.
619 This function is a possible cancellation points and therefore not
620 marked with __THROW. */
621 # ifndef __USE_FILE_OFFSET64
622 extern int mkstemp (char *__template) __nonnull ((1)) __wur;
625 extern int __REDIRECT (mkstemp, (char *__template), mkstemp64)
626 __nonnull ((1)) __wur;
628 # define mkstemp mkstemp64
631 # ifdef __USE_LARGEFILE64
632 extern int mkstemp64 (char *__template) __nonnull ((1)) __wur;
637 /* Create a unique temporary directory from TEMPLATE.
638 The last six characters of TEMPLATE must be "XXXXXX";
639 they are replaced with a string that makes the directory name unique.
640 Returns TEMPLATE, or a null pointer if it cannot get a unique name.
641 The directory is created mode 700. */
642 extern char *mkdtemp (char *__template) __THROW __nonnull ((1)) __wur;
646 __BEGIN_NAMESPACE_STD
647 /* Execute the given line as a shell command.
649 This function is a cancellation point and therefore not marked with
651 extern int system (__const char *__command) __wur;
655 #if 0 /* def __USE_GNU */
656 /* Return a malloc'd string containing the canonical absolute name of the
657 existing named file. */
658 extern char *canonicalize_file_name (__const char *__name)
659 __THROW __nonnull ((1)) __wur;
662 /* Return the canonical absolute name of file NAME. If RESOLVED is
663 null, the result is malloc'd; otherwise, if the canonical name is
664 PATH_MAX chars or more, returns null with `errno' set to
665 ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars,
666 returns the name in RESOLVED. */
667 /* we choose to handle __resolved==NULL as crash :) */
668 extern char *realpath (__const char *__restrict __name,
669 char *__restrict __resolved) __THROW __wur;
672 /* Shorthand for type of comparison functions. */
673 #ifndef __COMPAR_FN_T
674 # define __COMPAR_FN_T
675 typedef int (*__compar_fn_t) (__const void *, __const void *);
678 typedef __compar_fn_t comparison_fn_t;
682 __BEGIN_NAMESPACE_STD
683 /* Do a binary search for KEY in BASE, which consists of NMEMB elements
684 of SIZE bytes each, using COMPAR to perform the comparisons. */
685 extern void *bsearch (__const void *__key, __const void *__base,
686 size_t __nmemb, size_t __size, __compar_fn_t __compar)
687 __nonnull ((1, 2, 5)) __wur;
689 /* Sort NMEMB elements of BASE, of SIZE bytes each,
690 using COMPAR to perform the comparisons. */
691 extern void qsort (void *__base, size_t __nmemb, size_t __size,
692 __compar_fn_t __compar) __nonnull ((1, 4));
693 libc_hidden_proto(qsort)
696 /* Return the absolute value of X. */
697 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
698 extern long int labs (long int __x) __THROW __attribute__ ((__const__)) __wur;
702 __extension__ extern long long int llabs (long long int __x)
703 __THROW __attribute__ ((__const__)) __wur;
707 __BEGIN_NAMESPACE_STD
708 /* Return the `div_t', `ldiv_t' or `lldiv_t' representation
709 of the value of NUMER over DENOM. */
710 /* GCC may have built-ins for these someday. */
711 extern div_t div (int __numer, int __denom)
712 __THROW __attribute__ ((__const__)) __wur;
713 extern ldiv_t ldiv (long int __numer, long int __denom)
714 __THROW __attribute__ ((__const__)) __wur;
718 __BEGIN_NAMESPACE_C99
719 __extension__ extern lldiv_t lldiv (long long int __numer,
720 long long int __denom)
721 __THROW __attribute__ ((__const__)) __wur;
726 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED || defined __USE_BSD
727 /* Convert floating point numbers to strings. The returned values are
728 valid only until another call to the same function. */
730 # ifdef __UCLIBC_SUSV3_LEGACY__
733 /* Convert VALUE to a string with NDIGIT digits and return a pointer to
734 this. Set *DECPT with the position of the decimal character and *SIGN
735 with the sign of the number. */
736 extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt,
737 int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur;
739 /* Convert VALUE to a string rounded to NDIGIT decimal digits. Set *DECPT
740 with the position of the decimal character and *SIGN with the sign of
742 extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt,
743 int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur;
746 /* If possible convert VALUE to a string with NDIGIT significant digits.
747 Otherwise use exponential representation. The resulting string will
748 be written to BUF. */
749 extern char *gcvt (double __value, int __ndigit, char *__buf)
750 __THROW __nonnull ((3)) __wur;
751 # endif /* __UCLIBC_SUSV3_LEGACY__ */
753 # if 0 /*def __USE_MISC*/
754 /* Long double versions of above functions. */
755 extern char *qecvt (long double __value, int __ndigit,
756 int *__restrict __decpt, int *__restrict __sign)
757 __THROW __nonnull ((3, 4)) __wur;
758 extern char *qfcvt (long double __value, int __ndigit,
759 int *__restrict __decpt, int *__restrict __sign)
760 __THROW __nonnull ((3, 4)) __wur;
761 extern char *qgcvt (long double __value, int __ndigit, char *__buf)
762 __THROW __nonnull ((3)) __wur;
765 /* Reentrant version of the functions above which provide their own
767 extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt,
768 int *__restrict __sign, char *__restrict __buf,
769 size_t __len) __THROW __nonnull ((3, 4, 5));
770 extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt,
771 int *__restrict __sign, char *__restrict __buf,
772 size_t __len) __THROW __nonnull ((3, 4, 5));
774 extern int qecvt_r (long double __value, int __ndigit,
775 int *__restrict __decpt, int *__restrict __sign,
776 char *__restrict __buf, size_t __len)
777 __THROW __nonnull ((3, 4, 5));
778 extern int qfcvt_r (long double __value, int __ndigit,
779 int *__restrict __decpt, int *__restrict __sign,
780 char *__restrict __buf, size_t __len)
781 __THROW __nonnull ((3, 4, 5));
783 #endif /* use MISC || use X/Open Unix */
785 #ifdef __UCLIBC_HAS_WCHAR__
786 __BEGIN_NAMESPACE_STD
787 /* Return the length of the multibyte character
788 in S, which is no longer than N. */
789 extern int mblen (__const char *__s, size_t __n) __THROW __wur;
790 /* Return the length of the given multibyte character,
791 putting its `wchar_t' representation in *PWC. */
792 extern int mbtowc (wchar_t *__restrict __pwc,
793 __const char *__restrict __s, size_t __n) __THROW __wur;
794 /* Put the multibyte character represented
795 by WCHAR in S, returning its length. */
796 extern int wctomb (char *__s, wchar_t __wchar) __THROW __wur;
799 /* Convert a multibyte string to a wide char string. */
800 extern size_t mbstowcs (wchar_t *__restrict __pwcs,
801 __const char *__restrict __s, size_t __n) __THROW;
802 /* Convert a wide char string to multibyte string. */
803 extern size_t wcstombs (char *__restrict __s,
804 __const wchar_t *__restrict __pwcs, size_t __n)
807 #endif /* __UCLIBC_HAS_WCHAR__ */
811 /* Determine whether the string value of RESPONSE matches the affirmation
812 or negative response expression as specified by the LC_MESSAGES category
813 in the program's current locale. Returns 1 if affirmative, 0 if
814 negative, and -1 if not matching. */
815 extern int rpmatch (__const char *__response) __THROW __nonnull ((1)) __wur;
819 #ifdef __USE_XOPEN_EXTENDED
820 /* Parse comma separated suboption from *OPTIONP and match against
821 strings in TOKENS. If found return index and set *VALUEP to
822 optional value introduced by an equal sign. If the suboption is
823 not part of TOKENS return in *VALUEP beginning of unknown
824 suboption. On exit *OPTIONP is set to the beginning of the next
825 token or at the terminating NUL character. */
826 extern int getsubopt (char **__restrict __optionp,
827 char *__const *__restrict __tokens,
828 char **__restrict __valuep)
829 __THROW __nonnull ((1, 2, 3)) __wur;
834 # if defined __UCLIBC_HAS_CRYPT__
835 /* Setup DES tables according KEY. */
836 extern void setkey (__const char *__key) __THROW __nonnull ((1));
837 # endif /* __UCLIBC_HAS_CRYPT__ */
841 /* X/Open pseudo terminal handling. */
844 /* Return a master pseudo-terminal handle. */
845 extern int posix_openpt (int __oflag) __wur;
846 libc_hidden_proto(posix_openpt)
850 /* The next four functions all take a master pseudo-tty fd and
851 perform an operation on the associated slave: */
852 #ifdef __UCLIBC_HAS_PTY__
853 /* Chown the slave to the calling user. */
854 extern int grantpt (int __fd) __THROW;
856 /* Release an internal lock so the slave can be opened.
857 Call after grantpt(). */
858 extern int unlockpt (int __fd) __THROW;
860 /* Return the pathname of the pseudo terminal slave assoicated with
861 the master FD is open on, or NULL on errors.
862 The returned storage is good until the next call to this function. */
863 extern char *ptsname (int __fd) __THROW __wur;
864 #endif /* __UCLIBC_HAS_PTY__ */
868 # if defined __UCLIBC_HAS_PTY__
869 /* Store at most BUFLEN characters of the pathname of the slave pseudo
870 terminal associated with the master FD is open on in BUF.
871 Return 0 on success, otherwise an error number. */
872 extern int ptsname_r (int __fd, char *__buf, size_t __buflen)
873 __THROW __nonnull ((2));
874 libc_hidden_proto(ptsname_r)
876 # if defined __UCLIBC_HAS_GETPT__
877 /* Open a master pseudo terminal and return its file descriptor. */
878 extern int getpt (void);
882 #if 0 /* def __USE_BSD */
883 /* Put the 1 minute, 5 minute and 15 minute load averages into the first
884 NELEM elements of LOADAVG. Return the number written (never more than
885 three, but may be less than NELEM), or -1 if an error occurred. */
886 extern int getloadavg (double __loadavg[], int __nelem)
887 __THROW __nonnull ((1));
890 #ifdef __UCLIBC_HAS_ARC4RANDOM__
892 extern uint32_t arc4random(void);
893 extern void arc4random_stir(void);
894 libc_hidden_proto(arc4random_stir)
895 extern void arc4random_addrandom(unsigned char *, int);
898 #endif /* don't just need malloc and calloc */
899 #undef __need_malloc_and_calloc
903 #endif /* stdlib.h */