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; }) \
55 { .__in = (status) }).__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 # ifdef __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)
150 # define MB_CUR_MAX 1
155 __BEGIN_NAMESPACE_STD
156 #ifdef __UCLIBC_HAS_FLOATS__
157 /* Convert a string to a floating-point number. */
158 extern double atof (__const char *__nptr)
159 __THROW __attribute_pure__ __nonnull ((1)) __wur;
160 #endif /* __UCLIBC_HAS_FLOATS__ */
161 /* Convert a string to an integer. */
162 extern int atoi (__const char *__nptr)
163 __THROW __attribute_pure__ __nonnull ((1)) __wur;
164 libc_hidden_proto(atoi)
165 /* Convert a string to a long integer. */
166 extern long int atol (__const char *__nptr)
167 __THROW __attribute_pure__ __nonnull ((1)) __wur;
168 libc_hidden_proto(atol)
171 #if defined __USE_ISOC99 || defined __USE_MISC
172 __BEGIN_NAMESPACE_C99
173 /* Convert a string to a long long integer. */
174 __extension__ extern long long int atoll (__const char *__nptr)
175 __THROW __attribute_pure__ __nonnull ((1)) __wur;
179 #ifdef __UCLIBC_HAS_FLOATS__
180 __BEGIN_NAMESPACE_STD
181 /* Convert a string to a floating-point number. */
182 extern double strtod (__const char *__restrict __nptr,
183 char **__restrict __endptr)
184 __THROW __nonnull ((1)) __wur;
185 libc_hidden_proto(strtod)
189 __BEGIN_NAMESPACE_C99
190 /* Likewise for `float' and `long double' sizes of floating-point numbers. */
191 extern float strtof (__const char *__restrict __nptr,
192 char **__restrict __endptr) __THROW __nonnull ((1)) __wur;
194 extern long double strtold (__const char *__restrict __nptr,
195 char **__restrict __endptr)
196 __THROW __nonnull ((1)) __wur;
199 #endif /* __UCLIBC_HAS_FLOATS__ */
201 __BEGIN_NAMESPACE_STD
202 /* Convert a string to a long integer. */
203 extern long int strtol (__const char *__restrict __nptr,
204 char **__restrict __endptr, int __base)
205 __THROW __nonnull ((1)) __wur;
206 libc_hidden_proto(strtol)
207 /* Convert a string to an unsigned long integer. */
208 extern unsigned long int strtoul (__const char *__restrict __nptr,
209 char **__restrict __endptr, int __base)
210 __THROW __nonnull ((1)) __wur;
211 libc_hidden_proto(strtoul)
215 #include <sys/types.h> /* for u_quad_t */
217 /* Convert a string to a quadword integer. */
219 extern quad_t strtoq (__const char *__restrict __nptr,
220 char **__restrict __endptr, int __base)
221 __THROW __nonnull ((1)) __wur;
222 /* Convert a string to an unsigned quadword integer. */
224 extern u_quad_t strtouq (__const char *__restrict __nptr,
225 char **__restrict __endptr, int __base)
226 __THROW __nonnull ((1)) __wur;
227 #endif /* GCC and use BSD. */
229 #if defined __USE_ISOC99 || defined __USE_MISC
230 __BEGIN_NAMESPACE_C99
231 /* Convert a string to a quadword integer. */
233 extern long long int strtoll (__const char *__restrict __nptr,
234 char **__restrict __endptr, int __base)
235 __THROW __nonnull ((1)) __wur;
236 libc_hidden_proto(strtoll)
237 /* Convert a string to an unsigned quadword integer. */
239 extern unsigned long long int strtoull (__const char *__restrict __nptr,
240 char **__restrict __endptr, int __base)
241 __THROW __nonnull ((1)) __wur;
243 #endif /* ISO C99 or GCC and use MISC. */
246 #if defined __USE_GNU && defined __UCLIBC_HAS_XLOCALE__
247 /* The concept of one static locale per category is not very well
248 thought out. Many applications will need to process its data using
249 information from several different locales. Another problem is
250 the implementation of the internationalization handling in the
251 ISO C++ standard library. To support this another set of
252 the functions using locale data exist which take an additional
255 Attention: even though several *_l interfaces are part of POSIX:2008,
258 /* Structure for reentrant locale using functions. This is an
259 (almost) opaque type for the user level programs. */
260 # include <xlocale.h>
262 /* Special versions of the functions above which take the locale to
263 use as an additional parameter. */
264 extern long int strtol_l (__const char *__restrict __nptr,
265 char **__restrict __endptr, int __base,
266 __locale_t __loc) __THROW __nonnull ((1, 4)) __wur;
267 libc_hidden_proto(strtol_l)
269 extern unsigned long int strtoul_l (__const char *__restrict __nptr,
270 char **__restrict __endptr,
271 int __base, __locale_t __loc)
272 __THROW __nonnull ((1, 4)) __wur;
273 libc_hidden_proto(strtoul_l)
276 extern long long int strtoll_l (__const char *__restrict __nptr,
277 char **__restrict __endptr, int __base,
279 __THROW __nonnull ((1, 4)) __wur;
282 extern unsigned long long int strtoull_l (__const char *__restrict __nptr,
283 char **__restrict __endptr,
284 int __base, __locale_t __loc)
285 __THROW __nonnull ((1, 4)) __wur;
287 #ifdef __UCLIBC_HAS_FLOATS__
288 extern double strtod_l (__const char *__restrict __nptr,
289 char **__restrict __endptr, __locale_t __loc)
290 __THROW __nonnull ((1, 3)) __wur;
292 extern float strtof_l (__const char *__restrict __nptr,
293 char **__restrict __endptr, __locale_t __loc)
294 __THROW __nonnull ((1, 3)) __wur;
296 extern long double strtold_l (__const char *__restrict __nptr,
297 char **__restrict __endptr,
299 __THROW __nonnull ((1, 3)) __wur;
300 #endif /* __UCLIBC_HAS_FLOATS__ */
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. */
353 int rand_type; /* Type of random number generator. */
354 int rand_deg; /* Degree of random number generator. */
355 int rand_sep; /* Distance between front and rear. */
357 /* random_r.c, TYPE_x, DEG_x, SEP_x - small enough for int8_t */
358 int8_t rand_type; /* Type of random number generator. */
359 int8_t rand_deg; /* Degree of random number generator. */
360 int8_t rand_sep; /* Distance between front and rear. */
362 int32_t *end_ptr; /* Pointer behind state table. */
365 extern int random_r (struct random_data *__restrict __buf,
366 int32_t *__restrict __result) __THROW __nonnull ((1, 2));
367 libc_hidden_proto(random_r)
369 extern int srandom_r (unsigned int __seed, struct random_data *__buf)
370 __THROW __nonnull ((2));
371 libc_hidden_proto(srandom_r)
373 extern int initstate_r (unsigned int __seed, char *__restrict __statebuf,
375 struct random_data *__restrict __buf)
376 __THROW __nonnull ((2, 4));
377 libc_hidden_proto(initstate_r)
379 extern int setstate_r (char *__restrict __statebuf,
380 struct random_data *__restrict __buf)
381 __THROW __nonnull ((1, 2));
382 libc_hidden_proto(setstate_r)
383 # endif /* Use misc. */
384 #endif /* Use SVID || extended X/Open || BSD. */
387 __BEGIN_NAMESPACE_STD
388 /* Return a random integer between 0 and RAND_MAX inclusive. */
389 extern int rand (void) __THROW;
390 /* Seed the random number generator with the given number. */
391 extern void srand (unsigned int __seed) __THROW;
395 /* Reentrant interface according to POSIX.1. */
396 extern int rand_r (unsigned int *__seed) __THROW;
400 #if defined __USE_SVID || defined __USE_XOPEN
401 /* System V style 48-bit random number generator functions. */
403 #ifdef __UCLIBC_HAS_FLOATS__
404 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
405 extern double drand48 (void) __THROW;
406 extern double erand48 (unsigned short int __xsubi[3]) __THROW __nonnull ((1));
407 #endif /* __UCLIBC_HAS_FLOATS__ */
409 /* Return non-negative, long integer in [0,2^31). */
410 extern long int lrand48 (void) __THROW;
411 extern long int nrand48 (unsigned short int __xsubi[3])
412 __THROW __nonnull ((1));
414 /* Return signed, long integers in [-2^31,2^31). */
415 extern long int mrand48 (void) __THROW;
416 extern long int jrand48 (unsigned short int __xsubi[3])
417 __THROW __nonnull ((1));
419 /* Seed random number generator. */
420 extern void srand48 (long int __seedval) __THROW;
421 extern unsigned short int *seed48 (unsigned short int __seed16v[3])
422 __THROW __nonnull ((1));
423 extern void lcong48 (unsigned short int __param[7]) __THROW __nonnull ((1));
426 /* Data structure for communication with thread safe versions. This
427 type is to be regarded as opaque. It's only exported because users
428 have to allocate objects of this type. */
431 unsigned short int __x[3]; /* Current state. */
432 unsigned short int __old_x[3]; /* Old state. */
433 unsigned short int __c; /* Additive const. in congruential formula. */
434 unsigned short int __init; /* Flag for initializing. */
435 unsigned long long int __a; /* Factor in congruential formula. */
438 #ifdef __UCLIBC_HAS_FLOATS__
439 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
440 extern int drand48_r (struct drand48_data *__restrict __buffer,
441 double *__restrict __result) __THROW __nonnull ((1, 2));
442 extern int erand48_r (unsigned short int __xsubi[3],
443 struct drand48_data *__restrict __buffer,
444 double *__restrict __result) __THROW __nonnull ((1, 2));
445 libc_hidden_proto(erand48_r)
446 #endif /* __UCLIBC_HAS_FLOATS__ */
448 /* Return non-negative, long integer in [0,2^31). */
449 extern int lrand48_r (struct drand48_data *__restrict __buffer,
450 long int *__restrict __result)
451 __THROW __nonnull ((1, 2));
452 libc_hidden_proto(lrand48_r)
453 extern int nrand48_r (unsigned short int __xsubi[3],
454 struct drand48_data *__restrict __buffer,
455 long int *__restrict __result)
456 __THROW __nonnull ((1, 2));
457 libc_hidden_proto(nrand48_r)
459 /* Return signed, long integers in [-2^31,2^31). */
460 extern int mrand48_r (struct drand48_data *__restrict __buffer,
461 long int *__restrict __result)
462 __THROW __nonnull ((1, 2));
463 extern int jrand48_r (unsigned short int __xsubi[3],
464 struct drand48_data *__restrict __buffer,
465 long int *__restrict __result)
466 __THROW __nonnull ((1, 2));
467 libc_hidden_proto(jrand48_r)
469 /* Seed random number generator. */
470 extern int srand48_r (long int __seedval, struct drand48_data *__buffer)
471 __THROW __nonnull ((2));
472 libc_hidden_proto(srand48_r)
474 extern int seed48_r (unsigned short int __seed16v[3],
475 struct drand48_data *__buffer) __THROW __nonnull ((1, 2));
476 libc_hidden_proto(seed48_r)
478 extern int lcong48_r (unsigned short int __param[7],
479 struct drand48_data *__buffer)
480 __THROW __nonnull ((1, 2));
481 # endif /* Use misc. */
482 #endif /* Use SVID or X/Open. */
484 #endif /* don't just need malloc and calloc */
486 #ifndef __malloc_and_calloc_defined
487 # define __malloc_and_calloc_defined
488 __BEGIN_NAMESPACE_STD
489 /* Allocate SIZE bytes of memory. */
490 extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
491 /* We want the malloc symbols overridable at runtime
492 * libc_hidden_proto(malloc) */
493 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
494 extern void *calloc (size_t __nmemb, size_t __size)
495 __THROW __attribute_malloc__ __wur;
499 #ifndef __need_malloc_and_calloc
500 __BEGIN_NAMESPACE_STD
501 /* Re-allocate the previously allocated block
502 in PTR, making the new block SIZE bytes long. */
503 /* __attribute_malloc__ is not used, because if realloc returns
504 the same pointer that was passed to it, aliasing needs to be allowed
505 between objects pointed by the old and new pointers. */
506 extern void *realloc (void *__ptr, size_t __size)
507 __THROW __attribute_warn_unused_result__;
508 /* Free a block allocated by `malloc', `realloc' or `calloc'. */
509 extern void free (void *__ptr) __THROW;
512 #if 0 /*def __USE_MISC*/
513 /* Free a block. An alias for `free'. (Sun Unices). */
514 extern void cfree (void *__ptr) __THROW;
515 #endif /* Use misc. */
517 #if defined __USE_GNU || defined __USE_BSD || defined __USE_MISC
519 #endif /* Use GNU, BSD, or misc. */
521 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
522 /* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */
523 extern void *valloc (size_t __size) __THROW __attribute_malloc__ __wur;
526 #if defined __USE_XOPEN2K && defined __UCLIBC_HAS_ADVANCED_REALTIME__
527 /* Allocate memory of SIZE bytes with an alignment of ALIGNMENT. */
528 extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size)
529 __THROW __nonnull ((1)) __wur;
532 __BEGIN_NAMESPACE_STD
533 /* Abort execution and generate a core-dump. */
534 extern void abort (void) __THROW __attribute__ ((__noreturn__));
535 libc_hidden_proto(abort)
538 /* Register a function to be called when `exit' is called. */
539 extern int atexit (void (*__func) (void)) __THROW __nonnull ((1));
543 /* Register a function to be called with the status
544 given to `exit' and the given argument. */
545 extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg)
546 __THROW __nonnull ((1));
549 __BEGIN_NAMESPACE_STD
550 /* Call all functions registered with `atexit' and `on_exit',
551 in the reverse of the order in which they were registered,
552 perform stdio cleanup, and terminate program execution with STATUS. */
553 extern void exit (int __status) __THROW __attribute__ ((__noreturn__));
554 libc_hidden_proto(exit)
558 __BEGIN_NAMESPACE_C99
559 /* Terminate the program with STATUS without calling any of the
560 functions registered with `atexit' or `on_exit'. */
561 extern void _Exit (int __status) __THROW __attribute__ ((__noreturn__));
566 __BEGIN_NAMESPACE_STD
567 /* Return the value of envariable NAME, or NULL if it doesn't exist. */
568 extern char *getenv (__const char *__name) __THROW __nonnull ((1)) __wur;
569 libc_hidden_proto(getenv)
573 /* This function is similar to the above but returns NULL if the
574 programs is running with SUID or SGID enabled. */
575 extern char *__secure_getenv (__const char *__name)
576 __THROW __nonnull ((1)) __wur;
579 #if defined __USE_SVID || defined __USE_XOPEN
580 /* The SVID says this is in <stdio.h>, but this seems a better place. */
581 /* Put STRING, which is of the form "NAME=VALUE", in the environment.
582 If there is no `=', remove NAME from the environment. */
583 extern int putenv (char *__string) __THROW __nonnull ((1));
586 #if defined __USE_BSD || defined __USE_XOPEN2K
587 /* Set NAME to VALUE in the environment.
588 If REPLACE is nonzero, overwrite an existing value. */
589 extern int setenv (__const char *__name, __const char *__value, int __replace)
590 __THROW __nonnull ((2));
591 libc_hidden_proto(setenv)
593 /* Remove the variable NAME from the environment. */
594 extern int unsetenv (__const char *__name) __THROW;
595 libc_hidden_proto(unsetenv)
598 /* The following is used by uClibc in atexit.c and sysconf.c */
599 /* We have no limit when __UCLIBC_DYNAMIC_ATEXIT__ is enabled. */
600 #ifdef __UCLIBC_DYNAMIC_ATEXIT__
601 # define __UCLIBC_MAX_ATEXIT INT_MAX
603 # define __UCLIBC_MAX_ATEXIT 20
608 /* The `clearenv' was planned to be added to POSIX.1 but probably
609 never made it. Nevertheless the POSIX.9 standard (POSIX bindings
610 for Fortran 77) requires this function. */
611 extern int clearenv (void) __THROW;
615 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
616 # if defined __UCLIBC_SUSV3_LEGACY__
617 /* Generate a unique temporary file name from TEMPLATE.
618 The last six characters of TEMPLATE must be "XXXXXX";
619 they are replaced with a string that makes the file name unique.
620 Returns TEMPLATE, or a null pointer if it cannot get a unique file name. */
621 extern char *mktemp (char *__template) __THROW __nonnull ((1)) __wur;
624 /* Generate a unique temporary file name from TEMPLATE.
625 The last six characters of TEMPLATE must be "XXXXXX";
626 they are replaced with a string that makes the filename unique.
627 Returns a file descriptor open on the file for reading and writing,
628 or -1 if it cannot create a uniquely-named file.
630 This function is a possible cancellation point and therefore not
631 marked with __THROW. */
632 # ifndef __USE_FILE_OFFSET64
633 extern int mkstemp (char *__template) __nonnull ((1)) __wur;
636 extern int __REDIRECT (mkstemp, (char *__template), mkstemp64)
637 __nonnull ((1)) __wur;
639 # define mkstemp mkstemp64
642 # ifdef __USE_LARGEFILE64
643 extern int mkstemp64 (char *__template) __nonnull ((1)) __wur;
647 #if defined __USE_BSD || defined __USE_XOPEN2K8
648 /* Create a unique temporary directory from TEMPLATE.
649 The last six characters of TEMPLATE must be "XXXXXX";
650 they are replaced with a string that makes the directory name unique.
651 Returns TEMPLATE, or a null pointer if it cannot get a unique name.
652 The directory is created mode 700. */
653 extern char *mkdtemp (char *__template) __THROW __nonnull ((1)) __wur;
657 __BEGIN_NAMESPACE_STD
658 /* Execute the given line as a shell command.
660 This function is a cancellation point and therefore not marked with
662 extern int system (__const char *__command) __wur;
667 /* Return a malloc'd string containing the canonical absolute name of the
668 existing named file. */
669 extern char *canonicalize_file_name (__const char *__name)
670 __THROW __nonnull ((1)) __wur;
673 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
674 /* Return the canonical absolute name of file NAME. If RESOLVED is
675 null, the result is malloc'd; otherwise, if the canonical name is
676 PATH_MAX chars or more, returns null with `errno' set to
677 ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars,
678 returns the name in RESOLVED. */
679 extern char *realpath (__const char *__restrict __name,
680 char *__restrict __resolved) __THROW __wur;
681 libc_hidden_proto(realpath)
685 /* Shorthand for type of comparison functions. */
686 #ifndef __COMPAR_FN_T
687 # define __COMPAR_FN_T
688 typedef int (*__compar_fn_t) (__const void *, __const void *);
691 typedef __compar_fn_t comparison_fn_t;
695 __BEGIN_NAMESPACE_STD
696 /* Do a binary search for KEY in BASE, which consists of NMEMB elements
697 of SIZE bytes each, using COMPAR to perform the comparisons. */
698 extern void *bsearch (__const void *__key, __const void *__base,
699 size_t __nmemb, size_t __size, __compar_fn_t __compar)
700 __nonnull ((1, 2, 5)) __wur;
702 /* Sort NMEMB elements of BASE, of SIZE bytes each,
703 using COMPAR to perform the comparisons. */
704 extern void qsort (void *__base, size_t __nmemb, size_t __size,
705 __compar_fn_t __compar) __nonnull ((1, 4));
706 libc_hidden_proto(qsort)
709 /* Return the absolute value of X. */
710 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
711 extern long int labs (long int __x) __THROW __attribute__ ((__const__)) __wur;
715 __extension__ extern long long int llabs (long long int __x)
716 __THROW __attribute__ ((__const__)) __wur;
720 __BEGIN_NAMESPACE_STD
721 /* Return the `div_t', `ldiv_t' or `lldiv_t' representation
722 of the value of NUMER over DENOM. */
723 /* GCC may have built-ins for these someday. */
724 extern div_t div (int __numer, int __denom)
725 __THROW __attribute__ ((__const__)) __wur;
726 extern ldiv_t ldiv (long int __numer, long int __denom)
727 __THROW __attribute__ ((__const__)) __wur;
731 __BEGIN_NAMESPACE_C99
732 __extension__ extern lldiv_t lldiv (long long int __numer,
733 long long int __denom)
734 __THROW __attribute__ ((__const__)) __wur;
739 #if ( defined __USE_SVID || defined __USE_XOPEN_EXTENDED ) && defined __UCLIBC_HAS_FLOATS__
740 /* Convert floating point numbers to strings. The returned values are
741 valid only until another call to the same function. */
743 # ifdef __UCLIBC_SUSV3_LEGACY__
745 /* Convert VALUE to a string with NDIGIT digits and return a pointer to
746 this. Set *DECPT with the position of the decimal character and *SIGN
747 with the sign of the number. */
748 extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt,
749 int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur;
751 /* Convert VALUE to a string rounded to NDIGIT decimal digits. Set *DECPT
752 with the position of the decimal character and *SIGN with the sign of
754 extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt,
755 int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur;
758 /* If possible convert VALUE to a string with NDIGIT significant digits.
759 Otherwise use exponential representation. The resulting string will
760 be written to BUF. */
761 extern char *gcvt (double __value, int __ndigit, char *__buf)
762 __THROW __nonnull ((3)) __wur;
763 # endif /* __UCLIBC_SUSV3_LEGACY__ */
766 # if 0 /*def __USE_MISC*/
767 /* Long double versions of above functions. */
768 extern char *qecvt (long double __value, int __ndigit,
769 int *__restrict __decpt, int *__restrict __sign)
770 __THROW __nonnull ((3, 4)) __wur;
771 extern char *qfcvt (long double __value, int __ndigit,
772 int *__restrict __decpt, int *__restrict __sign)
773 __THROW __nonnull ((3, 4)) __wur;
774 extern char *qgcvt (long double __value, int __ndigit, char *__buf)
775 __THROW __nonnull ((3)) __wur;
778 /* Reentrant version of the functions above which provide their own
780 extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt,
781 int *__restrict __sign, char *__restrict __buf,
782 size_t __len) __THROW __nonnull ((3, 4, 5));
783 extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt,
784 int *__restrict __sign, char *__restrict __buf,
785 size_t __len) __THROW __nonnull ((3, 4, 5));
787 extern int qecvt_r (long double __value, int __ndigit,
788 int *__restrict __decpt, int *__restrict __sign,
789 char *__restrict __buf, size_t __len)
790 __THROW __nonnull ((3, 4, 5));
791 extern int qfcvt_r (long double __value, int __ndigit,
792 int *__restrict __decpt, int *__restrict __sign,
793 char *__restrict __buf, size_t __len)
794 __THROW __nonnull ((3, 4, 5));
796 #endif /* use MISC || use X/Open Unix */
799 #ifdef __UCLIBC_HAS_WCHAR__
800 __BEGIN_NAMESPACE_STD
801 /* Return the length of the multibyte character
802 in S, which is no longer than N. */
803 extern int mblen (__const char *__s, size_t __n) __THROW __wur;
804 /* Return the length of the given multibyte character,
805 putting its `wchar_t' representation in *PWC. */
806 extern int mbtowc (wchar_t *__restrict __pwc,
807 __const char *__restrict __s, size_t __n) __THROW __wur;
808 /* Put the multibyte character represented
809 by WCHAR in S, returning its length. */
810 extern int wctomb (char *__s, wchar_t __wchar) __THROW __wur;
813 /* Convert a multibyte string to a wide char string. */
814 extern size_t mbstowcs (wchar_t *__restrict __pwcs,
815 __const char *__restrict __s, size_t __n) __THROW;
816 /* Convert a wide char string to multibyte string. */
817 extern size_t wcstombs (char *__restrict __s,
818 __const wchar_t *__restrict __pwcs, size_t __n)
821 #endif /* __UCLIBC_HAS_WCHAR__ */
824 #if 0 /*def __USE_SVID*/
825 /* Determine whether the string value of RESPONSE matches the affirmation
826 or negative response expression as specified by the LC_MESSAGES category
827 in the program's current locale. Returns 1 if affirmative, 0 if
828 negative, and -1 if not matching. */
829 extern int rpmatch (__const char *__response) __THROW __nonnull ((1)) __wur;
833 #ifdef __USE_XOPEN_EXTENDED
834 /* Parse comma separated suboption from *OPTIONP and match against
835 strings in TOKENS. If found return index and set *VALUEP to
836 optional value introduced by an equal sign. If the suboption is
837 not part of TOKENS return in *VALUEP beginning of unknown
838 suboption. On exit *OPTIONP is set to the beginning of the next
839 token or at the terminating NUL character. */
840 extern int getsubopt (char **__restrict __optionp,
841 char *__const *__restrict __tokens,
842 char **__restrict __valuep)
843 __THROW __nonnull ((1, 2, 3)) __wur;
848 # if defined __UCLIBC_HAS_CRYPT__
849 /* Setup DES tables according KEY. */
850 extern void setkey (__const char *__key) __THROW __nonnull ((1));
851 # endif /* __UCLIBC_HAS_CRYPT__ */
855 /* X/Open pseudo terminal handling. */
858 /* Return a master pseudo-terminal handle. */
859 extern int posix_openpt (int __oflag) __wur;
860 libc_hidden_proto(posix_openpt)
864 /* The next four functions all take a master pseudo-tty fd and
865 perform an operation on the associated slave: */
867 #ifdef __UCLIBC_HAS_PTY__
868 /* Chown the slave to the calling user. */
869 extern int grantpt (int __fd) __THROW;
871 /* Release an internal lock so the slave can be opened.
872 Call after grantpt(). */
873 extern int unlockpt (int __fd) __THROW;
875 /* Return the pathname of the pseudo terminal slave assoicated with
876 the master FD is open on, or NULL on errors.
877 The returned storage is good until the next call to this function. */
878 extern char *ptsname (int __fd) __THROW __wur;
879 #endif /* __UCLIBC_HAS_PTY__ */
883 # if defined __UCLIBC_HAS_PTY__
884 /* Store at most BUFLEN characters of the pathname of the slave pseudo
885 terminal associated with the master FD is open on in BUF.
886 Return 0 on success, otherwise an error number. */
887 extern int ptsname_r (int __fd, char *__buf, size_t __buflen)
888 __THROW __nonnull ((2));
889 libc_hidden_proto(ptsname_r)
891 # if defined __UCLIBC_HAS_GETPT__
892 /* Open a master pseudo terminal and return its file descriptor. */
893 extern int getpt (void);
897 #if 0 /* def __USE_BSD */
898 /* Put the 1 minute, 5 minute and 15 minute load averages into the first
899 NELEM elements of LOADAVG. Return the number written (never more than
900 three, but may be less than NELEM), or -1 if an error occurred. */
901 extern int getloadavg (double __loadavg[], int __nelem)
902 __THROW __nonnull ((1));
905 #ifdef __UCLIBC_HAS_ARC4RANDOM__
907 extern uint32_t arc4random(void);
908 extern void arc4random_stir(void);
909 extern void arc4random_addrandom(unsigned char *, int);
913 extern int __drand48_iterate (unsigned short int xsubi[3], struct drand48_data *buffer) attribute_hidden;
915 /* Global state for non-reentrant functions. */
916 extern struct drand48_data __libc_drand48_data attribute_hidden;
919 #endif /* don't just need malloc and calloc */
920 #undef __need_malloc_and_calloc
924 #endif /* stdlib.h */