15af32e75SAxel Dörfler /* Copyright (C) 1991-99,2000,01,02 Free Software Foundation, Inc.
25af32e75SAxel Dörfler This file is part of the GNU C Library.
35af32e75SAxel Dörfler
45af32e75SAxel Dörfler The GNU C Library is free software; you can redistribute it and/or
55af32e75SAxel Dörfler modify it under the terms of the GNU Lesser General Public
65af32e75SAxel Dörfler License as published by the Free Software Foundation; either
75af32e75SAxel Dörfler version 2.1 of the License, or (at your option) any later version.
85af32e75SAxel Dörfler
95af32e75SAxel Dörfler The GNU C Library is distributed in the hope that it will be useful,
105af32e75SAxel Dörfler but WITHOUT ANY WARRANTY; without even the implied warranty of
115af32e75SAxel Dörfler MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
125af32e75SAxel Dörfler Lesser General Public License for more details.
135af32e75SAxel Dörfler
145af32e75SAxel Dörfler You should have received a copy of the GNU Lesser General Public
155af32e75SAxel Dörfler License along with the GNU C Library; if not, write to the Free
165af32e75SAxel Dörfler Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
175af32e75SAxel Dörfler 02111-1307 USA. */
185af32e75SAxel Dörfler
195af32e75SAxel Dörfler /*
205af32e75SAxel Dörfler * ISO C99 Standard: 7.20 General utilities <stdlib.h>
215af32e75SAxel Dörfler */
225af32e75SAxel Dörfler
235af32e75SAxel Dörfler #ifndef _STDLIB_H
245af32e75SAxel Dörfler
255af32e75SAxel Dörfler #include <features.h>
265af32e75SAxel Dörfler
275af32e75SAxel Dörfler /* Get size_t, wchar_t and NULL from <stddef.h>. */
285af32e75SAxel Dörfler #define __need_size_t
295af32e75SAxel Dörfler #ifndef __need_malloc_and_calloc
305af32e75SAxel Dörfler # define __need_wchar_t
315af32e75SAxel Dörfler # define __need_NULL
325af32e75SAxel Dörfler #endif
335af32e75SAxel Dörfler #include <stddef.h>
345af32e75SAxel Dörfler #include <stdint.h>
355af32e75SAxel Dörfler
365af32e75SAxel Dörfler __BEGIN_DECLS
375af32e75SAxel Dörfler
385af32e75SAxel Dörfler #ifndef __need_malloc_and_calloc
395af32e75SAxel Dörfler #define _STDLIB_H 1
405af32e75SAxel Dörfler
415af32e75SAxel Dörfler #if defined __USE_XOPEN && !defined _SYS_WAIT_H
425af32e75SAxel Dörfler /* XPG requires a few symbols from <sys/wait.h> being defined. */
435af32e75SAxel Dörfler # include <bits/waitflags.h>
445af32e75SAxel Dörfler # include <bits/waitstatus.h>
455af32e75SAxel Dörfler
465af32e75SAxel Dörfler # ifdef __USE_BSD
475af32e75SAxel Dörfler
485af32e75SAxel Dörfler /* Lots of hair to allow traditional BSD use of `union wait'
495af32e75SAxel Dörfler as well as POSIX.1 use of `int' for the status word. */
505af32e75SAxel Dörfler
515af32e75SAxel Dörfler # if defined __GNUC__ && !defined __cplusplus
525af32e75SAxel Dörfler # define __WAIT_INT(status) \
535af32e75SAxel Dörfler (__extension__ ({ union { __typeof(status) __in; int __i; } __u; \
545af32e75SAxel Dörfler __u.__in = (status); __u.__i; }))
555af32e75SAxel Dörfler # else
565af32e75SAxel Dörfler # define __WAIT_INT(status) (*(int *) &(status))
575af32e75SAxel Dörfler # endif
585af32e75SAxel Dörfler
595af32e75SAxel Dörfler /* This is the type of the argument to `wait'. The funky union
605af32e75SAxel Dörfler causes redeclarations with ether `int *' or `union wait *' to be
615af32e75SAxel Dörfler allowed without complaint. __WAIT_STATUS_DEFN is the type used in
625af32e75SAxel Dörfler the actual function definitions. */
635af32e75SAxel Dörfler
645af32e75SAxel Dörfler # if !defined __GNUC__ || __GNUC__ < 2 || defined __cplusplus
655af32e75SAxel Dörfler # define __WAIT_STATUS void *
665af32e75SAxel Dörfler # define __WAIT_STATUS_DEFN void *
675af32e75SAxel Dörfler # else
685af32e75SAxel Dörfler /* This works in GCC 2.6.1 and later. */
695af32e75SAxel Dörfler typedef union
705af32e75SAxel Dörfler {
715af32e75SAxel Dörfler union wait *__uptr;
725af32e75SAxel Dörfler int *__iptr;
735af32e75SAxel Dörfler } __WAIT_STATUS __attribute__ ((__transparent_union__));
745af32e75SAxel Dörfler # define __WAIT_STATUS_DEFN int *
755af32e75SAxel Dörfler # endif
765af32e75SAxel Dörfler
775af32e75SAxel Dörfler # else /* Don't use BSD. */
785af32e75SAxel Dörfler
795af32e75SAxel Dörfler # define __WAIT_INT(status) (status)
805af32e75SAxel Dörfler # define __WAIT_STATUS int *
815af32e75SAxel Dörfler # define __WAIT_STATUS_DEFN int *
825af32e75SAxel Dörfler
835af32e75SAxel Dörfler # endif /* Use BSD. */
845af32e75SAxel Dörfler
855af32e75SAxel Dörfler /* Define the macros <sys/wait.h> also would define this way. */
865af32e75SAxel Dörfler # define WEXITSTATUS(status) __WEXITSTATUS(__WAIT_INT(status))
875af32e75SAxel Dörfler # define WTERMSIG(status) __WTERMSIG(__WAIT_INT(status))
885af32e75SAxel Dörfler # define WSTOPSIG(status) __WSTOPSIG(__WAIT_INT(status))
895af32e75SAxel Dörfler # define WIFEXITED(status) __WIFEXITED(__WAIT_INT(status))
905af32e75SAxel Dörfler # define WIFSIGNALED(status) __WIFSIGNALED(__WAIT_INT(status))
915af32e75SAxel Dörfler # define WIFSTOPPED(status) __WIFSTOPPED(__WAIT_INT(status))
925af32e75SAxel Dörfler #endif /* X/Open and <sys/wait.h> not included. */
935af32e75SAxel Dörfler
945af32e75SAxel Dörfler __BEGIN_NAMESPACE_STD
955af32e75SAxel Dörfler /* Returned by `div'. */
965af32e75SAxel Dörfler typedef struct
975af32e75SAxel Dörfler {
985af32e75SAxel Dörfler int quot; /* Quotient. */
995af32e75SAxel Dörfler int rem; /* Remainder. */
1005af32e75SAxel Dörfler } div_t;
1015af32e75SAxel Dörfler
1025af32e75SAxel Dörfler /* Returned by `ldiv'. */
1035af32e75SAxel Dörfler #ifndef __ldiv_t_defined
1045af32e75SAxel Dörfler typedef struct
1055af32e75SAxel Dörfler {
1065af32e75SAxel Dörfler long int quot; /* Quotient. */
1075af32e75SAxel Dörfler long int rem; /* Remainder. */
1085af32e75SAxel Dörfler } ldiv_t;
1095af32e75SAxel Dörfler # define __ldiv_t_defined 1
1105af32e75SAxel Dörfler #endif
1115af32e75SAxel Dörfler __END_NAMESPACE_STD
1125af32e75SAxel Dörfler
1135af32e75SAxel Dörfler #if defined __USE_ISOC99 && !defined __lldiv_t_defined
1145af32e75SAxel Dörfler __BEGIN_NAMESPACE_C99
1155af32e75SAxel Dörfler /* Returned by `lldiv'. */
1165af32e75SAxel Dörfler __extension__ typedef struct
1175af32e75SAxel Dörfler {
1185af32e75SAxel Dörfler long long int quot; /* Quotient. */
1195af32e75SAxel Dörfler long long int rem; /* Remainder. */
1205af32e75SAxel Dörfler } lldiv_t;
1215af32e75SAxel Dörfler # define __lldiv_t_defined 1
1225af32e75SAxel Dörfler __END_NAMESPACE_C99
1235af32e75SAxel Dörfler #endif
1245af32e75SAxel Dörfler
1255af32e75SAxel Dörfler
1265af32e75SAxel Dörfler /* The largest number rand will return (same as INT_MAX). */
1275af32e75SAxel Dörfler #define RAND_MAX 2147483647
1285af32e75SAxel Dörfler
1295af32e75SAxel Dörfler
1305af32e75SAxel Dörfler /* We define these the same for all machines.
1315af32e75SAxel Dörfler Changes from this to the outside world should be done in `_exit'. */
1325af32e75SAxel Dörfler #define EXIT_FAILURE 1 /* Failing exit status. */
1335af32e75SAxel Dörfler #define EXIT_SUCCESS 0 /* Successful exit status. */
1345af32e75SAxel Dörfler
1355af32e75SAxel Dörfler
1365af32e75SAxel Dörfler /* Maximum length of a multibyte character in the current locale. */
1375af32e75SAxel Dörfler #define MB_CUR_MAX (__ctype_get_mb_cur_max ())
138e0eb1d38SOliver Tappe extern unsigned short __ctype_get_mb_cur_max(void);
1395af32e75SAxel Dörfler
1405af32e75SAxel Dörfler
1415af32e75SAxel Dörfler __BEGIN_NAMESPACE_STD
1425af32e75SAxel Dörfler /* Convert a string to a floating-point number. */
1435af32e75SAxel Dörfler extern double atof (__const char *__nptr) __THROW __attribute_pure__;
1445af32e75SAxel Dörfler /* Convert a string to an integer. */
1455af32e75SAxel Dörfler extern int atoi (__const char *__nptr) __THROW __attribute_pure__;
1465af32e75SAxel Dörfler /* Convert a string to a long integer. */
1475af32e75SAxel Dörfler extern long int atol (__const char *__nptr) __THROW __attribute_pure__;
1485af32e75SAxel Dörfler __END_NAMESPACE_STD
1495af32e75SAxel Dörfler
1505af32e75SAxel Dörfler #if defined __USE_ISOC99 || (defined __GLIBC_HAVE_LONG_LONG && defined __USE_MISC)
1515af32e75SAxel Dörfler __BEGIN_NAMESPACE_C99
1525af32e75SAxel Dörfler /* Convert a string to a long long integer. */
1535af32e75SAxel Dörfler __extension__ extern long long int atoll (__const char *__nptr)
1545af32e75SAxel Dörfler __THROW __attribute_pure__;
1555af32e75SAxel Dörfler __END_NAMESPACE_C99
1565af32e75SAxel Dörfler #endif
1575af32e75SAxel Dörfler
1585af32e75SAxel Dörfler __BEGIN_NAMESPACE_STD
1595af32e75SAxel Dörfler /* Convert a string to a floating-point number. */
1605af32e75SAxel Dörfler extern double strtod (__const char *__restrict __nptr,
1615af32e75SAxel Dörfler char **__restrict __endptr) __THROW;
1625af32e75SAxel Dörfler __END_NAMESPACE_STD
1635af32e75SAxel Dörfler
1645af32e75SAxel Dörfler #ifdef __USE_ISOC99
1655af32e75SAxel Dörfler __BEGIN_NAMESPACE_C99
1665af32e75SAxel Dörfler /* Likewise for `float' and `long double' sizes of floating-point numbers. */
1675af32e75SAxel Dörfler extern float strtof (__const char *__restrict __nptr,
1685af32e75SAxel Dörfler char **__restrict __endptr) __THROW;
1695af32e75SAxel Dörfler
1705af32e75SAxel Dörfler extern long double strtold (__const char *__restrict __nptr,
1715af32e75SAxel Dörfler char **__restrict __endptr) __THROW;
1725af32e75SAxel Dörfler __END_NAMESPACE_C99
1735af32e75SAxel Dörfler #endif
1745af32e75SAxel Dörfler
1755af32e75SAxel Dörfler __BEGIN_NAMESPACE_STD
1765af32e75SAxel Dörfler /* Convert a string to a long integer. */
1775af32e75SAxel Dörfler extern long int strtol (__const char *__restrict __nptr,
1785af32e75SAxel Dörfler char **__restrict __endptr, int __base) __THROW;
1795af32e75SAxel Dörfler /* Convert a string to an unsigned long integer. */
1805af32e75SAxel Dörfler extern unsigned long int strtoul (__const char *__restrict __nptr,
1815af32e75SAxel Dörfler char **__restrict __endptr, int __base)
1825af32e75SAxel Dörfler __THROW;
1835af32e75SAxel Dörfler __END_NAMESPACE_C99
1845af32e75SAxel Dörfler
1855af32e75SAxel Dörfler #if defined __GLIBC_HAVE_LONG_LONG && defined __USE_BSD
1865af32e75SAxel Dörfler /* Convert a string to a quadword integer. */
1875af32e75SAxel Dörfler __extension__
1885af32e75SAxel Dörfler extern long long int strtoq (__const char *__restrict __nptr,
1895af32e75SAxel Dörfler char **__restrict __endptr, int __base) __THROW;
1905af32e75SAxel Dörfler /* Convert a string to an unsigned quadword integer. */
1915af32e75SAxel Dörfler __extension__
1925af32e75SAxel Dörfler extern unsigned long long int strtouq (__const char *__restrict __nptr,
1935af32e75SAxel Dörfler char **__restrict __endptr, int __base)
1945af32e75SAxel Dörfler __THROW;
1955af32e75SAxel Dörfler #endif /* GCC and use BSD. */
1965af32e75SAxel Dörfler
1975af32e75SAxel Dörfler #if defined __USE_ISOC99 || (defined __GLIBC_HAVE_LONG_LONG && defined __USE_MISC)
1985af32e75SAxel Dörfler __BEGIN_NAMESPACE_C99
1995af32e75SAxel Dörfler /* Convert a string to a quadword integer. */
2005af32e75SAxel Dörfler __extension__
2015af32e75SAxel Dörfler extern long long int strtoll (__const char *__restrict __nptr,
2025af32e75SAxel Dörfler char **__restrict __endptr, int __base) __THROW;
2035af32e75SAxel Dörfler /* Convert a string to an unsigned quadword integer. */
2045af32e75SAxel Dörfler __extension__
2055af32e75SAxel Dörfler extern unsigned long long int strtoull (__const char *__restrict __nptr,
2065af32e75SAxel Dörfler char **__restrict __endptr, int __base)
2075af32e75SAxel Dörfler __THROW;
2085af32e75SAxel Dörfler __END_NAMESPACE_C99
2095af32e75SAxel Dörfler #endif /* ISO C99 or GCC and use MISC. */
2105af32e75SAxel Dörfler
2115af32e75SAxel Dörfler
2125af32e75SAxel Dörfler #ifdef __USE_GNU
2135af32e75SAxel Dörfler /* The concept of one static locale per category is not very well
2145af32e75SAxel Dörfler thought out. Many applications will need to process its data using
2155af32e75SAxel Dörfler information from several different locales. Another application is
2165af32e75SAxel Dörfler the implementation of the internationalization handling in the
2175af32e75SAxel Dörfler upcoming ISO C++ standard library. To support this another set of
2185af32e75SAxel Dörfler the functions using locale data exist which have an additional
2195af32e75SAxel Dörfler argument.
2205af32e75SAxel Dörfler
2215af32e75SAxel Dörfler Attention: all these functions are *not* standardized in any form.
2225af32e75SAxel Dörfler This is a proof-of-concept implementation. */
2235af32e75SAxel Dörfler
2245af32e75SAxel Dörfler /* Structure for reentrant locale using functions. This is an
2255af32e75SAxel Dörfler (almost) opaque type for the user level programs. */
2265af32e75SAxel Dörfler # include <xlocale.h>
2275af32e75SAxel Dörfler
2285af32e75SAxel Dörfler /* Special versions of the functions above which take the locale to
2295af32e75SAxel Dörfler use as an additional parameter. */
2305af32e75SAxel Dörfler extern long int strtol_l (__const char *__restrict __nptr,
2315af32e75SAxel Dörfler char **__restrict __endptr, int __base,
2325af32e75SAxel Dörfler __locale_t __loc) __THROW;
2335af32e75SAxel Dörfler
2345af32e75SAxel Dörfler extern unsigned long int strtoul_l (__const char *__restrict __nptr,
2355af32e75SAxel Dörfler char **__restrict __endptr,
2365af32e75SAxel Dörfler int __base, __locale_t __loc) __THROW;
2375af32e75SAxel Dörfler
2385af32e75SAxel Dörfler __extension__
2395af32e75SAxel Dörfler extern long long int strtoll_l (__const char *__restrict __nptr,
2405af32e75SAxel Dörfler char **__restrict __endptr, int __base,
2415af32e75SAxel Dörfler __locale_t __loc) __THROW;
2425af32e75SAxel Dörfler
2435af32e75SAxel Dörfler __extension__
2445af32e75SAxel Dörfler extern unsigned long long int strtoull_l (__const char *__restrict __nptr,
2455af32e75SAxel Dörfler char **__restrict __endptr,
2465af32e75SAxel Dörfler int __base, __locale_t __loc)
2475af32e75SAxel Dörfler __THROW;
2485af32e75SAxel Dörfler
2495af32e75SAxel Dörfler extern double strtod_l (__const char *__restrict __nptr,
2505af32e75SAxel Dörfler char **__restrict __endptr, __locale_t __loc)
2515af32e75SAxel Dörfler __THROW;
2525af32e75SAxel Dörfler
2535af32e75SAxel Dörfler extern float strtof_l (__const char *__restrict __nptr,
2545af32e75SAxel Dörfler char **__restrict __endptr, __locale_t __loc) __THROW;
2555af32e75SAxel Dörfler
2565af32e75SAxel Dörfler extern long double strtold_l (__const char *__restrict __nptr,
2575af32e75SAxel Dörfler char **__restrict __endptr,
2585af32e75SAxel Dörfler __locale_t __loc) __THROW;
2595af32e75SAxel Dörfler #endif /* GNU */
2605af32e75SAxel Dörfler
2615af32e75SAxel Dörfler
2625af32e75SAxel Dörfler /* The internal entry points for `strtoX' take an extra flag argument
2635af32e75SAxel Dörfler saying whether or not to parse locale-dependent number grouping. */
2645af32e75SAxel Dörfler
2655af32e75SAxel Dörfler extern double __strtod_internal (__const char *__restrict __nptr,
2665af32e75SAxel Dörfler char **__restrict __endptr, int __group)
2675af32e75SAxel Dörfler __THROW;
2685af32e75SAxel Dörfler extern float __strtof_internal (__const char *__restrict __nptr,
2695af32e75SAxel Dörfler char **__restrict __endptr, int __group)
2705af32e75SAxel Dörfler __THROW;
2715af32e75SAxel Dörfler extern long double __strtold_internal (__const char *__restrict __nptr,
2725af32e75SAxel Dörfler char **__restrict __endptr,
2735af32e75SAxel Dörfler int __group) __THROW;
2745af32e75SAxel Dörfler #ifndef __strtol_internal_defined
2755af32e75SAxel Dörfler extern long int __strtol_internal (__const char *__restrict __nptr,
2765af32e75SAxel Dörfler char **__restrict __endptr,
2775af32e75SAxel Dörfler int __base, int __group) __THROW;
2785af32e75SAxel Dörfler # define __strtol_internal_defined 1
2795af32e75SAxel Dörfler #endif
2805af32e75SAxel Dörfler #ifndef __strtoul_internal_defined
2815af32e75SAxel Dörfler extern unsigned long int __strtoul_internal (__const char *__restrict __nptr,
2825af32e75SAxel Dörfler char **__restrict __endptr,
2835af32e75SAxel Dörfler int __base, int __group) __THROW;
2845af32e75SAxel Dörfler # define __strtoul_internal_defined 1
2855af32e75SAxel Dörfler #endif
2865af32e75SAxel Dörfler #if defined __GNUC__ || defined __USE_ISOC99
2875af32e75SAxel Dörfler # ifndef __strtoll_internal_defined
2885af32e75SAxel Dörfler __extension__
2895af32e75SAxel Dörfler extern long long int __strtoll_internal (__const char *__restrict __nptr,
2905af32e75SAxel Dörfler char **__restrict __endptr,
2915af32e75SAxel Dörfler int __base, int __group) __THROW;
2925af32e75SAxel Dörfler # define __strtoll_internal_defined 1
2935af32e75SAxel Dörfler # endif
2945af32e75SAxel Dörfler # ifndef __strtoull_internal_defined
2955af32e75SAxel Dörfler __extension__
2965af32e75SAxel Dörfler extern unsigned long long int __strtoull_internal (__const char *
2975af32e75SAxel Dörfler __restrict __nptr,
2985af32e75SAxel Dörfler char **__restrict __endptr,
2995af32e75SAxel Dörfler int __base, int __group)
3005af32e75SAxel Dörfler __THROW;
3015af32e75SAxel Dörfler # define __strtoull_internal_defined 1
3025af32e75SAxel Dörfler # endif
3035af32e75SAxel Dörfler #endif /* GCC */
3045af32e75SAxel Dörfler
3055af32e75SAxel Dörfler #ifdef __USE_EXTERN_INLINES
3065af32e75SAxel Dörfler /* Define inline functions which call the internal entry points. */
3075af32e75SAxel Dörfler
3085af32e75SAxel Dörfler __BEGIN_NAMESPACE_STD
309*2a868d76SJérôme Duval __extern_inline double
strtod(__const char * __restrict __nptr,char ** __restrict __endptr)3105af32e75SAxel Dörfler strtod (__const char *__restrict __nptr, char **__restrict __endptr) __THROW
3115af32e75SAxel Dörfler {
3125af32e75SAxel Dörfler return __strtod_internal (__nptr, __endptr, 0);
3135af32e75SAxel Dörfler }
314*2a868d76SJérôme Duval __extern_inline long int
strtol(__const char * __restrict __nptr,char ** __restrict __endptr,int __base)3155af32e75SAxel Dörfler strtol (__const char *__restrict __nptr, char **__restrict __endptr,
3165af32e75SAxel Dörfler int __base) __THROW
3175af32e75SAxel Dörfler {
3185af32e75SAxel Dörfler return __strtol_internal (__nptr, __endptr, __base, 0);
3195af32e75SAxel Dörfler }
320*2a868d76SJérôme Duval __extern_inline unsigned long int
strtoul(__const char * __restrict __nptr,char ** __restrict __endptr,int __base)3215af32e75SAxel Dörfler strtoul (__const char *__restrict __nptr, char **__restrict __endptr,
3225af32e75SAxel Dörfler int __base) __THROW
3235af32e75SAxel Dörfler {
3245af32e75SAxel Dörfler return __strtoul_internal (__nptr, __endptr, __base, 0);
3255af32e75SAxel Dörfler }
3265af32e75SAxel Dörfler __END_NAMESPACE_STD
3275af32e75SAxel Dörfler
3285af32e75SAxel Dörfler # ifdef __USE_ISOC99
3295af32e75SAxel Dörfler __BEGIN_NAMESPACE_C99
330*2a868d76SJérôme Duval __extern_inline float
strtof(__const char * __restrict __nptr,char ** __restrict __endptr)3315af32e75SAxel Dörfler strtof (__const char *__restrict __nptr, char **__restrict __endptr) __THROW
3325af32e75SAxel Dörfler {
3335af32e75SAxel Dörfler return __strtof_internal (__nptr, __endptr, 0);
3345af32e75SAxel Dörfler }
335*2a868d76SJérôme Duval __extern_inline long double
strtold(__const char * __restrict __nptr,char ** __restrict __endptr)3365af32e75SAxel Dörfler strtold (__const char *__restrict __nptr, char **__restrict __endptr) __THROW
3375af32e75SAxel Dörfler {
3385af32e75SAxel Dörfler return __strtold_internal (__nptr, __endptr, 0);
3395af32e75SAxel Dörfler }
3405af32e75SAxel Dörfler __END_NAMESPACE_C99
3415af32e75SAxel Dörfler # endif
3425af32e75SAxel Dörfler
3435af32e75SAxel Dörfler # ifdef __USE_BSD
344*2a868d76SJérôme Duval __extension__ __extern_inline long long int
strtoq(__const char * __restrict __nptr,char ** __restrict __endptr,int __base)3455af32e75SAxel Dörfler strtoq (__const char *__restrict __nptr, char **__restrict __endptr,
3465af32e75SAxel Dörfler int __base) __THROW
3475af32e75SAxel Dörfler {
3485af32e75SAxel Dörfler return __strtoll_internal (__nptr, __endptr, __base, 0);
3495af32e75SAxel Dörfler }
350*2a868d76SJérôme Duval __extension__ __extern_inline unsigned long long int
strtouq(__const char * __restrict __nptr,char ** __restrict __endptr,int __base)3515af32e75SAxel Dörfler strtouq (__const char *__restrict __nptr, char **__restrict __endptr,
3525af32e75SAxel Dörfler int __base) __THROW
3535af32e75SAxel Dörfler {
3545af32e75SAxel Dörfler return __strtoull_internal (__nptr, __endptr, __base, 0);
3555af32e75SAxel Dörfler }
3565af32e75SAxel Dörfler # endif
3575af32e75SAxel Dörfler
3585af32e75SAxel Dörfler # if defined __USE_MISC || defined __USE_ISOC99
3595af32e75SAxel Dörfler __BEGIN_NAMESPACE_C99
360*2a868d76SJérôme Duval __extension__ __extern_inline long long int
strtoll(__const char * __restrict __nptr,char ** __restrict __endptr,int __base)3615af32e75SAxel Dörfler strtoll (__const char *__restrict __nptr, char **__restrict __endptr,
3625af32e75SAxel Dörfler int __base) __THROW
3635af32e75SAxel Dörfler {
3645af32e75SAxel Dörfler return __strtoll_internal (__nptr, __endptr, __base, 0);
3655af32e75SAxel Dörfler }
366*2a868d76SJérôme Duval __extension__ __extern_inline unsigned long long int
strtoull(__const char * __restrict __nptr,char ** __restrict __endptr,int __base)3675af32e75SAxel Dörfler strtoull (__const char * __restrict __nptr, char **__restrict __endptr,
3685af32e75SAxel Dörfler int __base) __THROW
3695af32e75SAxel Dörfler {
3705af32e75SAxel Dörfler return __strtoull_internal (__nptr, __endptr, __base, 0);
3715af32e75SAxel Dörfler }
3725af32e75SAxel Dörfler __END_NAMESPACE_C99
3735af32e75SAxel Dörfler # endif
3745af32e75SAxel Dörfler
3755af32e75SAxel Dörfler __BEGIN_NAMESPACE_STD
376*2a868d76SJérôme Duval __extern_inline double
atof(__const char * __nptr)3775af32e75SAxel Dörfler atof (__const char *__nptr) __THROW
3785af32e75SAxel Dörfler {
3795af32e75SAxel Dörfler return strtod (__nptr, (char **) NULL);
3805af32e75SAxel Dörfler }
381*2a868d76SJérôme Duval __extern_inline int
atoi(__const char * __nptr)3825af32e75SAxel Dörfler atoi (__const char *__nptr) __THROW
3835af32e75SAxel Dörfler {
3845af32e75SAxel Dörfler return (int) strtol (__nptr, (char **) NULL, 10);
3855af32e75SAxel Dörfler }
386*2a868d76SJérôme Duval __extern_inline long int
atol(__const char * __nptr)3875af32e75SAxel Dörfler atol (__const char *__nptr) __THROW
3885af32e75SAxel Dörfler {
3895af32e75SAxel Dörfler return strtol (__nptr, (char **) NULL, 10);
3905af32e75SAxel Dörfler }
3915af32e75SAxel Dörfler __END_NAMESPACE_STD
3925af32e75SAxel Dörfler
3935af32e75SAxel Dörfler # if defined __USE_MISC || defined __USE_ISOC99
3945af32e75SAxel Dörfler __BEGIN_NAMESPACE_C99
395*2a868d76SJérôme Duval __extension__ __extern_inline long long int
atoll(__const char * __nptr)3965af32e75SAxel Dörfler atoll (__const char *__nptr) __THROW
3975af32e75SAxel Dörfler {
3985af32e75SAxel Dörfler return strtoll (__nptr, (char **) NULL, 10);
3995af32e75SAxel Dörfler }
4005af32e75SAxel Dörfler __END_NAMESPACE_C99
4015af32e75SAxel Dörfler # endif
4025af32e75SAxel Dörfler #endif /* Optimizing and Inlining. */
4035af32e75SAxel Dörfler
4045af32e75SAxel Dörfler
4055af32e75SAxel Dörfler #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED
4065af32e75SAxel Dörfler /* Convert N to base 64 using the digits "./0-9A-Za-z", least-significant
4075af32e75SAxel Dörfler digit first. Returns a pointer to static storage overwritten by the
4085af32e75SAxel Dörfler next call. */
4095af32e75SAxel Dörfler extern char *l64a (long int __n) __THROW;
4105af32e75SAxel Dörfler
4115af32e75SAxel Dörfler /* Read a number from a string S in base 64 as above. */
4125af32e75SAxel Dörfler extern long int a64l (__const char *__s) __THROW __attribute_pure__;
4135af32e75SAxel Dörfler
4145af32e75SAxel Dörfler #endif /* Use SVID || extended X/Open. */
4155af32e75SAxel Dörfler
4165af32e75SAxel Dörfler #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED || defined __USE_BSD
4175af32e75SAxel Dörfler # include <sys/types.h> /* we need int32_t... */
4185af32e75SAxel Dörfler
4195af32e75SAxel Dörfler /* These are the functions that actually do things. The `random', `srandom',
4205af32e75SAxel Dörfler `initstate' and `setstate' functions are those from BSD Unices.
4215af32e75SAxel Dörfler The `rand' and `srand' functions are required by the ANSI standard.
4225af32e75SAxel Dörfler We provide both interfaces to the same random number generator. */
4235af32e75SAxel Dörfler /* Return a random long integer between 0 and RAND_MAX inclusive. */
4245af32e75SAxel Dörfler extern long int random (void) __THROW;
4255af32e75SAxel Dörfler
4265af32e75SAxel Dörfler /* Seed the random number generator with the given number. */
4275af32e75SAxel Dörfler extern void srandom (unsigned int __seed) __THROW;
4285af32e75SAxel Dörfler
4295af32e75SAxel Dörfler /* Initialize the random number generator to use state buffer STATEBUF,
4305af32e75SAxel Dörfler of length STATELEN, and seed it with SEED. Optimal lengths are 8, 16,
4315af32e75SAxel Dörfler 32, 64, 128 and 256, the bigger the better; values less than 8 will
4325af32e75SAxel Dörfler cause an error and values greater than 256 will be rounded down. */
4335af32e75SAxel Dörfler extern char *initstate (unsigned int __seed, char *__statebuf,
4345af32e75SAxel Dörfler size_t __statelen) __THROW;
4355af32e75SAxel Dörfler
4365af32e75SAxel Dörfler /* Switch the random number generator to state buffer STATEBUF,
4375af32e75SAxel Dörfler which should have been previously initialized by `initstate'. */
4385af32e75SAxel Dörfler extern char *setstate (char *__statebuf) __THROW;
4395af32e75SAxel Dörfler
4405af32e75SAxel Dörfler
4415af32e75SAxel Dörfler # ifdef __USE_MISC
4425af32e75SAxel Dörfler /* Reentrant versions of the `random' family of functions.
4435af32e75SAxel Dörfler These functions all use the following data structure to contain
4445af32e75SAxel Dörfler state, rather than global state variables. */
4455af32e75SAxel Dörfler
4465af32e75SAxel Dörfler struct random_data
4475af32e75SAxel Dörfler {
4485af32e75SAxel Dörfler int32_t *fptr; /* Front pointer. */
4495af32e75SAxel Dörfler int32_t *rptr; /* Rear pointer. */
4505af32e75SAxel Dörfler int32_t *state; /* Array of state values. */
4515af32e75SAxel Dörfler int rand_type; /* Type of random number generator. */
4525af32e75SAxel Dörfler int rand_deg; /* Degree of random number generator. */
4535af32e75SAxel Dörfler int rand_sep; /* Distance between front and rear. */
4545af32e75SAxel Dörfler int32_t *end_ptr; /* Pointer behind state table. */
4555af32e75SAxel Dörfler };
4565af32e75SAxel Dörfler
4575af32e75SAxel Dörfler extern int random_r (struct random_data *__restrict __buf,
4585af32e75SAxel Dörfler int32_t *__restrict __result) __THROW;
4595af32e75SAxel Dörfler
4605af32e75SAxel Dörfler extern int srandom_r (unsigned int __seed, struct random_data *__buf) __THROW;
4615af32e75SAxel Dörfler
4625af32e75SAxel Dörfler extern int initstate_r (unsigned int __seed, char *__restrict __statebuf,
4635af32e75SAxel Dörfler size_t __statelen,
4645af32e75SAxel Dörfler struct random_data *__restrict __buf) __THROW;
4655af32e75SAxel Dörfler
4665af32e75SAxel Dörfler extern int setstate_r (char *__restrict __statebuf,
4675af32e75SAxel Dörfler struct random_data *__restrict __buf) __THROW;
4685af32e75SAxel Dörfler # endif /* Use misc. */
4695af32e75SAxel Dörfler #endif /* Use SVID || extended X/Open || BSD. */
4705af32e75SAxel Dörfler
4715af32e75SAxel Dörfler
4725af32e75SAxel Dörfler __BEGIN_NAMESPACE_STD
4735af32e75SAxel Dörfler /* Return a random integer between 0 and RAND_MAX inclusive. */
4745af32e75SAxel Dörfler extern int rand (void) __THROW;
4755af32e75SAxel Dörfler /* Seed the random number generator with the given number. */
4765af32e75SAxel Dörfler extern void srand (unsigned int __seed) __THROW;
4775af32e75SAxel Dörfler __END_NAMESPACE_STD
4785af32e75SAxel Dörfler
4795af32e75SAxel Dörfler #ifdef __USE_POSIX
4805af32e75SAxel Dörfler /* Reentrant interface according to POSIX.1. */
4815af32e75SAxel Dörfler extern int rand_r (unsigned int *__seed) __THROW;
4825af32e75SAxel Dörfler #endif
4835af32e75SAxel Dörfler
4845af32e75SAxel Dörfler
4855af32e75SAxel Dörfler #if defined __USE_SVID || defined __USE_XOPEN
4865af32e75SAxel Dörfler /* System V style 48-bit random number generator functions. */
4875af32e75SAxel Dörfler
4885af32e75SAxel Dörfler /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
4895af32e75SAxel Dörfler extern double drand48 (void) __THROW;
4905af32e75SAxel Dörfler extern double erand48 (unsigned short int __xsubi[3]) __THROW;
4915af32e75SAxel Dörfler
4925af32e75SAxel Dörfler /* Return non-negative, long integer in [0,2^31). */
4935af32e75SAxel Dörfler extern long int lrand48 (void) __THROW;
4945af32e75SAxel Dörfler extern long int nrand48 (unsigned short int __xsubi[3]) __THROW;
4955af32e75SAxel Dörfler
4965af32e75SAxel Dörfler /* Return signed, long integers in [-2^31,2^31). */
4975af32e75SAxel Dörfler extern long int mrand48 (void) __THROW;
4985af32e75SAxel Dörfler extern long int jrand48 (unsigned short int __xsubi[3]) __THROW;
4995af32e75SAxel Dörfler
5005af32e75SAxel Dörfler /* Seed random number generator. */
5015af32e75SAxel Dörfler extern void srand48 (long int __seedval) __THROW;
5025af32e75SAxel Dörfler extern unsigned short int *seed48 (unsigned short int __seed16v[3]) __THROW;
5035af32e75SAxel Dörfler extern void lcong48 (unsigned short int __param[7]) __THROW;
5045af32e75SAxel Dörfler
5055af32e75SAxel Dörfler # ifdef __USE_MISC
5065af32e75SAxel Dörfler /* Data structure for communication with thread safe versions. This
5075af32e75SAxel Dörfler type is to be regarded as opaque. It's only exported because users
5085af32e75SAxel Dörfler have to allocate objects of this type. */
5095af32e75SAxel Dörfler struct drand48_data
5105af32e75SAxel Dörfler {
5115af32e75SAxel Dörfler unsigned short int __x[3]; /* Current state. */
5125af32e75SAxel Dörfler unsigned short int __old_x[3]; /* Old state. */
5135af32e75SAxel Dörfler unsigned short int __c; /* Additive const. in congruential formula. */
5145af32e75SAxel Dörfler unsigned short int __init; /* Flag for initializing. */
5155af32e75SAxel Dörfler unsigned long long int __a; /* Factor in congruential formula. */
5165af32e75SAxel Dörfler };
5175af32e75SAxel Dörfler
5185af32e75SAxel Dörfler /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
5195af32e75SAxel Dörfler extern int drand48_r (struct drand48_data *__restrict __buffer,
5205af32e75SAxel Dörfler double *__restrict __result) __THROW;
5215af32e75SAxel Dörfler extern int erand48_r (unsigned short int __xsubi[3],
5225af32e75SAxel Dörfler struct drand48_data *__restrict __buffer,
5235af32e75SAxel Dörfler double *__restrict __result) __THROW;
5245af32e75SAxel Dörfler
5255af32e75SAxel Dörfler /* Return non-negative, long integer in [0,2^31). */
5265af32e75SAxel Dörfler extern int lrand48_r (struct drand48_data *__restrict __buffer,
5275af32e75SAxel Dörfler long int *__restrict __result) __THROW;
5285af32e75SAxel Dörfler extern int nrand48_r (unsigned short int __xsubi[3],
5295af32e75SAxel Dörfler struct drand48_data *__restrict __buffer,
5305af32e75SAxel Dörfler long int *__restrict __result) __THROW;
5315af32e75SAxel Dörfler
5325af32e75SAxel Dörfler /* Return signed, long integers in [-2^31,2^31). */
5335af32e75SAxel Dörfler extern int mrand48_r (struct drand48_data *__restrict __buffer,
5345af32e75SAxel Dörfler long int *__restrict __result) __THROW;
5355af32e75SAxel Dörfler extern int jrand48_r (unsigned short int __xsubi[3],
5365af32e75SAxel Dörfler struct drand48_data *__restrict __buffer,
5375af32e75SAxel Dörfler long int *__restrict __result) __THROW;
5385af32e75SAxel Dörfler
5395af32e75SAxel Dörfler /* Seed random number generator. */
5405af32e75SAxel Dörfler extern int srand48_r (long int __seedval, struct drand48_data *__buffer)
5415af32e75SAxel Dörfler __THROW;
5425af32e75SAxel Dörfler
5435af32e75SAxel Dörfler extern int seed48_r (unsigned short int __seed16v[3],
5445af32e75SAxel Dörfler struct drand48_data *__buffer) __THROW;
5455af32e75SAxel Dörfler
5465af32e75SAxel Dörfler extern int lcong48_r (unsigned short int __param[7],
5475af32e75SAxel Dörfler struct drand48_data *__buffer) __THROW;
5485af32e75SAxel Dörfler # endif /* Use misc. */
5495af32e75SAxel Dörfler #endif /* Use SVID or X/Open. */
5505af32e75SAxel Dörfler
5515af32e75SAxel Dörfler #endif /* don't just need malloc and calloc */
5525af32e75SAxel Dörfler
5535af32e75SAxel Dörfler #ifndef __malloc_and_calloc_defined
5545af32e75SAxel Dörfler # define __malloc_and_calloc_defined
5555af32e75SAxel Dörfler __BEGIN_NAMESPACE_STD
5565af32e75SAxel Dörfler /* Allocate SIZE bytes of memory. */
5575af32e75SAxel Dörfler extern void *malloc (size_t __size) __THROW __attribute_malloc__;
5585af32e75SAxel Dörfler /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
5595af32e75SAxel Dörfler extern void *calloc (size_t __nmemb, size_t __size)
5605af32e75SAxel Dörfler __THROW __attribute_malloc__;
5615af32e75SAxel Dörfler __END_NAMESPACE_STD
5625af32e75SAxel Dörfler #endif
5635af32e75SAxel Dörfler
5645af32e75SAxel Dörfler #ifndef __need_malloc_and_calloc
5655af32e75SAxel Dörfler __BEGIN_NAMESPACE_STD
5665af32e75SAxel Dörfler /* Re-allocate the previously allocated block
5675af32e75SAxel Dörfler in PTR, making the new block SIZE bytes long. */
5685af32e75SAxel Dörfler extern void *realloc (void *__ptr, size_t __size) __THROW __attribute_malloc__;
5695af32e75SAxel Dörfler /* Free a block allocated by `malloc', `realloc' or `calloc'. */
5705af32e75SAxel Dörfler extern void free (void *__ptr) __THROW;
5715af32e75SAxel Dörfler __END_NAMESPACE_STD
5725af32e75SAxel Dörfler
5735af32e75SAxel Dörfler #ifdef __USE_MISC
5745af32e75SAxel Dörfler /* Free a block. An alias for `free'. (Sun Unices). */
5755af32e75SAxel Dörfler extern void cfree (void *__ptr) __THROW;
5765af32e75SAxel Dörfler #endif /* Use misc. */
5775af32e75SAxel Dörfler
5785af32e75SAxel Dörfler #if defined __USE_GNU || defined __USE_BSD || defined __USE_MISC
5795af32e75SAxel Dörfler # include <alloca.h>
5805af32e75SAxel Dörfler #endif /* Use GNU, BSD, or misc. */
5815af32e75SAxel Dörfler
5825af32e75SAxel Dörfler #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
5835af32e75SAxel Dörfler /* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */
5845af32e75SAxel Dörfler extern void *valloc (size_t __size) __THROW __attribute_malloc__;
5855af32e75SAxel Dörfler #endif
5865af32e75SAxel Dörfler
5875af32e75SAxel Dörfler #ifdef __USE_XOPEN2K
5885af32e75SAxel Dörfler /* Allocate memory of SIZE bytes with an alignment of ALIGNMENT. */
5895af32e75SAxel Dörfler extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size)
5905af32e75SAxel Dörfler __THROW __attribute_malloc__;
5915af32e75SAxel Dörfler #endif
5925af32e75SAxel Dörfler
5935af32e75SAxel Dörfler __BEGIN_NAMESPACE_STD
5945af32e75SAxel Dörfler /* Abort execution and generate a core-dump. */
5955af32e75SAxel Dörfler extern void abort (void) __THROW __attribute__ ((__noreturn__));
5965af32e75SAxel Dörfler
5975af32e75SAxel Dörfler
5985af32e75SAxel Dörfler /* Register a function to be called when `exit' is called. */
5995af32e75SAxel Dörfler extern int atexit (void (*__func) (void)) __THROW;
6005af32e75SAxel Dörfler __END_NAMESPACE_STD
6015af32e75SAxel Dörfler
6025af32e75SAxel Dörfler #ifdef __USE_MISC
6035af32e75SAxel Dörfler /* Register a function to be called with the status
6045af32e75SAxel Dörfler given to `exit' and the given argument. */
6055af32e75SAxel Dörfler extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg)
6065af32e75SAxel Dörfler __THROW;
6075af32e75SAxel Dörfler #endif
6085af32e75SAxel Dörfler
6095af32e75SAxel Dörfler __BEGIN_NAMESPACE_STD
6105af32e75SAxel Dörfler /* Call all functions registered with `atexit' and `on_exit',
6115af32e75SAxel Dörfler in the reverse of the order in which they were registered
6125af32e75SAxel Dörfler perform stdio cleanup, and terminate program execution with STATUS. */
6135af32e75SAxel Dörfler extern void exit (int __status) __THROW __attribute__ ((__noreturn__));
6145af32e75SAxel Dörfler __END_NAMESPACE_STD
6155af32e75SAxel Dörfler
6165af32e75SAxel Dörfler #ifdef __USE_ISOC99
6175af32e75SAxel Dörfler __BEGIN_NAMESPACE_C99
6185af32e75SAxel Dörfler /* Terminate the program with STATUS without calling any of the
6195af32e75SAxel Dörfler functions registered with `atexit' or `on_exit'. */
6205af32e75SAxel Dörfler extern void _Exit (int __status) __THROW __attribute__ ((__noreturn__));
6215af32e75SAxel Dörfler __END_NAMESPACE_C99
6225af32e75SAxel Dörfler #endif
6235af32e75SAxel Dörfler
6245af32e75SAxel Dörfler
6255af32e75SAxel Dörfler __BEGIN_NAMESPACE_STD
6265af32e75SAxel Dörfler /* Return the value of envariable NAME, or NULL if it doesn't exist. */
6275af32e75SAxel Dörfler extern char *getenv (__const char *__name) __THROW;
6285af32e75SAxel Dörfler __END_NAMESPACE_STD
6295af32e75SAxel Dörfler
6305af32e75SAxel Dörfler /* This function is similar to the above but returns NULL if the
6315af32e75SAxel Dörfler programs is running with SUID or SGID enabled. */
6325af32e75SAxel Dörfler extern char *__secure_getenv (__const char *__name) __THROW;
6335af32e75SAxel Dörfler
6345af32e75SAxel Dörfler #if defined __USE_SVID || defined __USE_XOPEN
6355af32e75SAxel Dörfler /* The SVID says this is in <stdio.h>, but this seems a better place. */
6365af32e75SAxel Dörfler /* Put STRING, which is of the form "NAME=VALUE", in the environment.
6375af32e75SAxel Dörfler If there is no `=', remove NAME from the environment. */
6385af32e75SAxel Dörfler extern int putenv (char *__string) __THROW;
6395af32e75SAxel Dörfler #endif
6405af32e75SAxel Dörfler
6415af32e75SAxel Dörfler #if defined __USE_BSD || defined __USE_XOPEN2K
6425af32e75SAxel Dörfler /* Set NAME to VALUE in the environment.
6435af32e75SAxel Dörfler If REPLACE is nonzero, overwrite an existing value. */
6445af32e75SAxel Dörfler extern int setenv (__const char *__name, __const char *__value, int __replace)
6455af32e75SAxel Dörfler __THROW;
6465af32e75SAxel Dörfler
6475af32e75SAxel Dörfler /* Remove the variable NAME from the environment. */
6485af32e75SAxel Dörfler extern int unsetenv (__const char *__name) __THROW;
6495af32e75SAxel Dörfler #endif
6505af32e75SAxel Dörfler
6515af32e75SAxel Dörfler #ifdef __USE_MISC
6525af32e75SAxel Dörfler /* The `clearenv' was planned to be added to POSIX.1 but probably
6535af32e75SAxel Dörfler never made it. Nevertheless the POSIX.9 standard (POSIX bindings
6545af32e75SAxel Dörfler for Fortran 77) requires this function. */
6555af32e75SAxel Dörfler extern int clearenv (void) __THROW;
6565af32e75SAxel Dörfler #endif
6575af32e75SAxel Dörfler
6585af32e75SAxel Dörfler
6595af32e75SAxel Dörfler #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
6605af32e75SAxel Dörfler /* Generate a unique temporary file name from TEMPLATE.
6615af32e75SAxel Dörfler The last six characters of TEMPLATE must be "XXXXXX";
6625af32e75SAxel Dörfler they are replaced with a string that makes the file name unique.
6635af32e75SAxel Dörfler Returns TEMPLATE, or a null pointer if it cannot get a unique file name. */
6645af32e75SAxel Dörfler extern char *mktemp (char *__template) __THROW;
6655af32e75SAxel Dörfler
6665af32e75SAxel Dörfler /* Generate a unique temporary file name from TEMPLATE.
6675af32e75SAxel Dörfler The last six characters of TEMPLATE must be "XXXXXX";
6685af32e75SAxel Dörfler they are replaced with a string that makes the filename unique.
6695af32e75SAxel Dörfler Returns a file descriptor open on the file for reading and writing,
6705af32e75SAxel Dörfler or -1 if it cannot create a uniquely-named file. */
6715af32e75SAxel Dörfler # ifndef __USE_FILE_OFFSET64
6725af32e75SAxel Dörfler extern int mkstemp (char *__template) __THROW;
6735af32e75SAxel Dörfler # else
6745af32e75SAxel Dörfler # ifdef __REDIRECT
6755af32e75SAxel Dörfler extern int __REDIRECT (mkstemp, (char *__template) __THROW, mkstemp64);
6765af32e75SAxel Dörfler # else
6775af32e75SAxel Dörfler # define mkstemp mkstemp64
6785af32e75SAxel Dörfler # endif
6795af32e75SAxel Dörfler # endif
6805af32e75SAxel Dörfler # ifdef __USE_LARGEFILE64
6815af32e75SAxel Dörfler extern int mkstemp64 (char *__template) __THROW;
6825af32e75SAxel Dörfler # endif
6835af32e75SAxel Dörfler #endif
6845af32e75SAxel Dörfler
6855af32e75SAxel Dörfler #ifdef __USE_BSD
6865af32e75SAxel Dörfler /* Create a unique temporary directory from TEMPLATE.
6875af32e75SAxel Dörfler The last six characters of TEMPLATE must be "XXXXXX";
6885af32e75SAxel Dörfler they are replaced with a string that makes the directory name unique.
6895af32e75SAxel Dörfler Returns TEMPLATE, or a null pointer if it cannot get a unique name.
6905af32e75SAxel Dörfler The directory is created mode 700. */
6915af32e75SAxel Dörfler extern char *mkdtemp (char *__template) __THROW;
6925af32e75SAxel Dörfler #endif
6935af32e75SAxel Dörfler
6945af32e75SAxel Dörfler
6955af32e75SAxel Dörfler __BEGIN_NAMESPACE_STD
6965af32e75SAxel Dörfler /* Execute the given line as a shell command. */
6975af32e75SAxel Dörfler extern int system (__const char *__command) __THROW;
6985af32e75SAxel Dörfler __END_NAMESPACE_STD
6995af32e75SAxel Dörfler
7005af32e75SAxel Dörfler
7015af32e75SAxel Dörfler #ifdef __USE_GNU
7025af32e75SAxel Dörfler /* Return a malloc'd string containing the canonical absolute name of the
7035af32e75SAxel Dörfler named file. The last file name component need not exist, and may be a
7045af32e75SAxel Dörfler symlink to a nonexistent file. */
7055af32e75SAxel Dörfler extern char *canonicalize_file_name (__const char *__name) __THROW;
7065af32e75SAxel Dörfler #endif
7075af32e75SAxel Dörfler
7085af32e75SAxel Dörfler #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
7095af32e75SAxel Dörfler /* Return the canonical absolute name of file NAME. The last file name
7105af32e75SAxel Dörfler component need not exist, and may be a symlink to a nonexistent file.
7115af32e75SAxel Dörfler If RESOLVED is null, the result is malloc'd; otherwise, if the canonical
7125af32e75SAxel Dörfler name is PATH_MAX chars or more, returns null with `errno' set to
7135af32e75SAxel Dörfler ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, returns the
7145af32e75SAxel Dörfler name in RESOLVED. */
7155af32e75SAxel Dörfler extern char *realpath (__const char *__restrict __name,
7165af32e75SAxel Dörfler char *__restrict __resolved) __THROW;
7175af32e75SAxel Dörfler #endif
7185af32e75SAxel Dörfler
7195af32e75SAxel Dörfler
7205af32e75SAxel Dörfler /* Shorthand for type of comparison functions. */
7215af32e75SAxel Dörfler #ifndef __COMPAR_FN_T
7225af32e75SAxel Dörfler # define __COMPAR_FN_T
7235af32e75SAxel Dörfler typedef int (*__compar_fn_t) (__const void *, __const void *);
7245af32e75SAxel Dörfler
7255af32e75SAxel Dörfler # ifdef __USE_GNU
7265af32e75SAxel Dörfler typedef __compar_fn_t comparison_fn_t;
7275af32e75SAxel Dörfler # endif
7285af32e75SAxel Dörfler #endif
7295af32e75SAxel Dörfler
7305af32e75SAxel Dörfler __BEGIN_NAMESPACE_STD
7315af32e75SAxel Dörfler /* Do a binary search for KEY in BASE, which consists of NMEMB elements
7325af32e75SAxel Dörfler of SIZE bytes each, using COMPAR to perform the comparisons. */
7335af32e75SAxel Dörfler extern void *bsearch (__const void *__key, __const void *__base,
7345af32e75SAxel Dörfler size_t __nmemb, size_t __size, __compar_fn_t __compar);
7355af32e75SAxel Dörfler
7365af32e75SAxel Dörfler /* Sort NMEMB elements of BASE, of SIZE bytes each,
7375af32e75SAxel Dörfler using COMPAR to perform the comparisons. */
7385af32e75SAxel Dörfler extern void qsort (void *__base, size_t __nmemb, size_t __size,
7395af32e75SAxel Dörfler __compar_fn_t __compar);
7405af32e75SAxel Dörfler
7415af32e75SAxel Dörfler
7425af32e75SAxel Dörfler /* Return the absolute value of X. */
7435af32e75SAxel Dörfler extern int abs (int __x) __THROW __attribute__ ((__const__));
7445af32e75SAxel Dörfler extern long int labs (long int __x) __THROW __attribute__ ((__const__));
7455af32e75SAxel Dörfler __END_NAMESPACE_STD
7465af32e75SAxel Dörfler
7475af32e75SAxel Dörfler #ifdef __USE_ISOC99
7485af32e75SAxel Dörfler __extension__ extern long long int llabs (long long int __x)
7495af32e75SAxel Dörfler __THROW __attribute__ ((__const__));
7505af32e75SAxel Dörfler #endif
7515af32e75SAxel Dörfler
7525af32e75SAxel Dörfler
7535af32e75SAxel Dörfler __BEGIN_NAMESPACE_STD
7545af32e75SAxel Dörfler /* Return the `div_t', `ldiv_t' or `lldiv_t' representation
7555af32e75SAxel Dörfler of the value of NUMER over DENOM. */
7565af32e75SAxel Dörfler /* GCC may have built-ins for these someday. */
7575af32e75SAxel Dörfler extern div_t div (int __numer, int __denom)
7585af32e75SAxel Dörfler __THROW __attribute__ ((__const__));
7595af32e75SAxel Dörfler extern ldiv_t ldiv (long int __numer, long int __denom)
7605af32e75SAxel Dörfler __THROW __attribute__ ((__const__));
7615af32e75SAxel Dörfler __END_NAMESPACE_STD
7625af32e75SAxel Dörfler
7635af32e75SAxel Dörfler #ifdef __USE_ISOC99
7645af32e75SAxel Dörfler __BEGIN_NAMESPACE_C99
7655af32e75SAxel Dörfler __extension__ extern lldiv_t lldiv (long long int __numer,
7665af32e75SAxel Dörfler long long int __denom)
7675af32e75SAxel Dörfler __THROW __attribute__ ((__const__));
7685af32e75SAxel Dörfler __END_NAMESPACE_C99
7695af32e75SAxel Dörfler #endif
7705af32e75SAxel Dörfler
7715af32e75SAxel Dörfler
7725af32e75SAxel Dörfler #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED
7735af32e75SAxel Dörfler /* Convert floating point numbers to strings. The returned values are
7745af32e75SAxel Dörfler valid only until another call to the same function. */
7755af32e75SAxel Dörfler
7765af32e75SAxel Dörfler /* Convert VALUE to a string with NDIGIT digits and return a pointer to
7775af32e75SAxel Dörfler this. Set *DECPT with the position of the decimal character and *SIGN
7785af32e75SAxel Dörfler with the sign of the number. */
7795af32e75SAxel Dörfler extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt,
7805af32e75SAxel Dörfler int *__restrict __sign) __THROW;
7815af32e75SAxel Dörfler
7825af32e75SAxel Dörfler /* Convert VALUE to a string rounded to NDIGIT decimal digits. Set *DECPT
7835af32e75SAxel Dörfler with the position of the decimal character and *SIGN with the sign of
7845af32e75SAxel Dörfler the number. */
7855af32e75SAxel Dörfler extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt,
7865af32e75SAxel Dörfler int *__restrict __sign) __THROW;
7875af32e75SAxel Dörfler
7885af32e75SAxel Dörfler /* If possible convert VALUE to a string with NDIGIT significant digits.
7895af32e75SAxel Dörfler Otherwise use exponential representation. The resulting string will
7905af32e75SAxel Dörfler be written to BUF. */
7915af32e75SAxel Dörfler extern char *gcvt (double __value, int __ndigit, char *__buf) __THROW;
7925af32e75SAxel Dörfler
7935af32e75SAxel Dörfler
7945af32e75SAxel Dörfler # ifdef __USE_MISC
7955af32e75SAxel Dörfler /* Long double versions of above functions. */
7965af32e75SAxel Dörfler extern char *qecvt (long double __value, int __ndigit,
7975af32e75SAxel Dörfler int *__restrict __decpt, int *__restrict __sign) __THROW;
7985af32e75SAxel Dörfler extern char *qfcvt (long double __value, int __ndigit,
7995af32e75SAxel Dörfler int *__restrict __decpt, int *__restrict __sign) __THROW;
8005af32e75SAxel Dörfler extern char *qgcvt (long double __value, int __ndigit, char *__buf) __THROW;
8015af32e75SAxel Dörfler
8025af32e75SAxel Dörfler
8035af32e75SAxel Dörfler /* Reentrant version of the functions above which provide their own
8045af32e75SAxel Dörfler buffers. */
8055af32e75SAxel Dörfler extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt,
8065af32e75SAxel Dörfler int *__restrict __sign, char *__restrict __buf,
8075af32e75SAxel Dörfler size_t __len) __THROW;
8085af32e75SAxel Dörfler extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt,
8095af32e75SAxel Dörfler int *__restrict __sign, char *__restrict __buf,
8105af32e75SAxel Dörfler size_t __len) __THROW;
8115af32e75SAxel Dörfler
8125af32e75SAxel Dörfler extern int qecvt_r (long double __value, int __ndigit,
8135af32e75SAxel Dörfler int *__restrict __decpt, int *__restrict __sign,
8145af32e75SAxel Dörfler char *__restrict __buf, size_t __len) __THROW;
8155af32e75SAxel Dörfler extern int qfcvt_r (long double __value, int __ndigit,
8165af32e75SAxel Dörfler int *__restrict __decpt, int *__restrict __sign,
8175af32e75SAxel Dörfler char *__restrict __buf, size_t __len) __THROW;
8185af32e75SAxel Dörfler # endif /* misc */
8195af32e75SAxel Dörfler #endif /* use MISC || use X/Open Unix */
8205af32e75SAxel Dörfler
8215af32e75SAxel Dörfler
8225af32e75SAxel Dörfler __BEGIN_NAMESPACE_STD
8235af32e75SAxel Dörfler /* Return the length of the multibyte character
8245af32e75SAxel Dörfler in S, which is no longer than N. */
8255af32e75SAxel Dörfler extern int mblen (__const char *__s, size_t __n) __THROW;
8265af32e75SAxel Dörfler /* Return the length of the given multibyte character,
8275af32e75SAxel Dörfler putting its `wchar_t' representation in *PWC. */
8285af32e75SAxel Dörfler extern int mbtowc (wchar_t *__restrict __pwc,
8295af32e75SAxel Dörfler __const char *__restrict __s, size_t __n) __THROW;
8305af32e75SAxel Dörfler /* Put the multibyte character represented
8315af32e75SAxel Dörfler by WCHAR in S, returning its length. */
8325af32e75SAxel Dörfler extern int wctomb (char *__s, wchar_t __wchar) __THROW;
8335af32e75SAxel Dörfler
8345af32e75SAxel Dörfler
8355af32e75SAxel Dörfler /* Convert a multibyte string to a wide char string. */
8365af32e75SAxel Dörfler extern size_t mbstowcs (wchar_t *__restrict __pwcs,
8375af32e75SAxel Dörfler __const char *__restrict __s, size_t __n) __THROW;
8385af32e75SAxel Dörfler /* Convert a wide char string to multibyte string. */
8395af32e75SAxel Dörfler extern size_t wcstombs (char *__restrict __s,
8405af32e75SAxel Dörfler __const wchar_t *__restrict __pwcs, size_t __n)
8415af32e75SAxel Dörfler __THROW;
8425af32e75SAxel Dörfler __END_NAMESPACE_STD
8435af32e75SAxel Dörfler
8445af32e75SAxel Dörfler
8455af32e75SAxel Dörfler #ifdef __USE_SVID
8465af32e75SAxel Dörfler /* Determine whether the string value of RESPONSE matches the affirmation
8475af32e75SAxel Dörfler or negative response expression as specified by the LC_MESSAGES category
8485af32e75SAxel Dörfler in the program's current locale. Returns 1 if affirmative, 0 if
8495af32e75SAxel Dörfler negative, and -1 if not matching. */
8505af32e75SAxel Dörfler extern int rpmatch (__const char *__response) __THROW;
8515af32e75SAxel Dörfler #endif
8525af32e75SAxel Dörfler
8535af32e75SAxel Dörfler
8545af32e75SAxel Dörfler #ifdef __USE_XOPEN_EXTENDED
8555af32e75SAxel Dörfler /* Parse comma separated suboption from *OPTIONP and match against
8565af32e75SAxel Dörfler strings in TOKENS. If found return index and set *VALUEP to
8575af32e75SAxel Dörfler optional value introduced by an equal sign. If the suboption is
8585af32e75SAxel Dörfler not part of TOKENS return in *VALUEP beginning of unknown
8595af32e75SAxel Dörfler suboption. On exit *OPTIONP is set to the beginning of the next
8605af32e75SAxel Dörfler token or at the terminating NUL character. */
8615af32e75SAxel Dörfler extern int getsubopt (char **__restrict __optionp,
8625af32e75SAxel Dörfler char *__const *__restrict __tokens,
8635af32e75SAxel Dörfler char **__restrict __valuep) __THROW;
8645af32e75SAxel Dörfler #endif
8655af32e75SAxel Dörfler
8665af32e75SAxel Dörfler
8675af32e75SAxel Dörfler #ifdef __USE_XOPEN
8685af32e75SAxel Dörfler /* Setup DES tables according KEY. */
8695af32e75SAxel Dörfler extern void setkey (__const char *__key) __THROW;
8705af32e75SAxel Dörfler #endif
8715af32e75SAxel Dörfler
8725af32e75SAxel Dörfler
8735af32e75SAxel Dörfler /* X/Open pseudo terminal handling. */
8745af32e75SAxel Dörfler
8755af32e75SAxel Dörfler #ifdef __USE_XOPEN2K
8765af32e75SAxel Dörfler /* Return a master pseudo-terminal handle. */
8775af32e75SAxel Dörfler extern int posix_openpt (int __oflag) __THROW;
8785af32e75SAxel Dörfler #endif
8795af32e75SAxel Dörfler
8805af32e75SAxel Dörfler #ifdef __USE_XOPEN
8815af32e75SAxel Dörfler /* The next four functions all take a master pseudo-tty fd and
8825af32e75SAxel Dörfler perform an operation on the associated slave: */
8835af32e75SAxel Dörfler
8845af32e75SAxel Dörfler /* Chown the slave to the calling user. */
8855af32e75SAxel Dörfler extern int grantpt (int __fd) __THROW;
8865af32e75SAxel Dörfler
8875af32e75SAxel Dörfler /* Release an internal lock so the slave can be opened.
8885af32e75SAxel Dörfler Call after grantpt(). */
8895af32e75SAxel Dörfler extern int unlockpt (int __fd) __THROW;
8905af32e75SAxel Dörfler
8915af32e75SAxel Dörfler /* Return the pathname of the pseudo terminal slave assoicated with
8925af32e75SAxel Dörfler the master FD is open on, or NULL on errors.
8935af32e75SAxel Dörfler The returned storage is good until the next call to this function. */
8945af32e75SAxel Dörfler extern char *ptsname (int __fd) __THROW;
8955af32e75SAxel Dörfler #endif
8965af32e75SAxel Dörfler
8975af32e75SAxel Dörfler #ifdef __USE_GNU
8985af32e75SAxel Dörfler /* Store at most BUFLEN characters of the pathname of the slave pseudo
8995af32e75SAxel Dörfler terminal associated with the master FD is open on in BUF.
9005af32e75SAxel Dörfler Return 0 on success, otherwise an error number. */
9015af32e75SAxel Dörfler extern int ptsname_r (int __fd, char *__buf, size_t __buflen) __THROW;
9025af32e75SAxel Dörfler
9035af32e75SAxel Dörfler /* Open a master pseudo terminal and return its file descriptor. */
9045af32e75SAxel Dörfler extern int getpt (void) __THROW;
9055af32e75SAxel Dörfler #endif
9065af32e75SAxel Dörfler
9075af32e75SAxel Dörfler #ifdef __USE_BSD
9085af32e75SAxel Dörfler /* Put the 1 minute, 5 minute and 15 minute load averages into the first
9095af32e75SAxel Dörfler NELEM elements of LOADAVG. Return the number written (never more than
9105af32e75SAxel Dörfler three, but may be less than NELEM), or -1 if an error occurred. */
9115af32e75SAxel Dörfler extern int getloadavg (double __loadavg[], int __nelem) __THROW;
9125af32e75SAxel Dörfler #endif
9135af32e75SAxel Dörfler
9145af32e75SAxel Dörfler #endif /* don't just need malloc and calloc */
9155af32e75SAxel Dörfler #undef __need_malloc_and_calloc
9165af32e75SAxel Dörfler
9175af32e75SAxel Dörfler __END_DECLS
9185af32e75SAxel Dörfler
9195af32e75SAxel Dörfler #endif /* stdlib.h */
920