/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
* ISO C99 Standard: 7.20 General utilities <stdlib.h>
#define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
#include <bits/libc-header-start.h>
/* Get size_t, wchar_t and NULL from <stddef.h>. */
#if (defined __USE_XOPEN || defined __USE_XOPEN2K8) && !defined _SYS_WAIT_H
/* XPG requires a few symbols from <sys/wait.h> being defined. */
# include <bits/waitflags.h>
# include <bits/waitstatus.h>
/* Define the macros <sys/wait.h> also would define this way. */
# define WEXITSTATUS(status) __WEXITSTATUS (status)
# define WTERMSIG(status) __WTERMSIG (status)
# define WSTOPSIG(status) __WSTOPSIG (status)
# define WIFEXITED(status) __WIFEXITED (status)
# define WIFSIGNALED(status) __WIFSIGNALED (status)
# define WIFSTOPPED(status) __WIFSTOPPED (status)
# define WIFCONTINUED(status) __WIFCONTINUED (status)
#endif /* X/Open or XPG7 and <sys/wait.h> not included. */
/* _FloatN API tests for enablement. */
int quot; /* Quotient. */
int rem; /* Remainder. */
/* Returned by `ldiv'. */
long int quot; /* Quotient. */
long int rem; /* Remainder. */
# define __ldiv_t_defined 1
#if defined __USE_ISOC99 && !defined __lldiv_t_defined
/* Returned by `lldiv'. */
__extension__ typedef struct
long long int quot; /* Quotient. */
long long int rem; /* Remainder. */
# define __lldiv_t_defined 1
/* The largest number rand will return (same as INT_MAX). */
#define RAND_MAX 2147483647
/* We define these the same for all machines.
Changes from this to the outside world should be done in `_exit'. */
#define EXIT_FAILURE 1 /* Failing exit status. */
#define EXIT_SUCCESS 0 /* Successful exit status. */
/* Maximum length of a multibyte character in the current locale. */
#define MB_CUR_MAX (__ctype_get_mb_cur_max ())
extern size_t __ctype_get_mb_cur_max (void) __THROW __wur;
/* Convert a string to a floating-point number. */
extern double atof (const char *__nptr)
__THROW __attribute_pure__ __nonnull ((1)) __wur;
/* Convert a string to an integer. */
extern int atoi (const char *__nptr)
__THROW __attribute_pure__ __nonnull ((1)) __wur;
/* Convert a string to a long integer. */
extern long int atol (const char *__nptr)
__THROW __attribute_pure__ __nonnull ((1)) __wur;
/* Convert a string to a long long integer. */
__extension__ extern long long int atoll (const char *__nptr)
__THROW __attribute_pure__ __nonnull ((1)) __wur;
/* Convert a string to a floating-point number. */
extern double strtod (const char *__restrict __nptr,
char **__restrict __endptr)
/* Likewise for `float' and `long double' sizes of floating-point numbers. */
extern float strtof (const char *__restrict __nptr,
char **__restrict __endptr) __THROW __nonnull ((1));
extern long double strtold (const char *__restrict __nptr,
char **__restrict __endptr)
/* Likewise for '_FloatN' and '_FloatNx'. */
#if __HAVE_FLOAT16 && __GLIBC_USE (IEC_60559_TYPES_EXT)
extern _Float16 strtof16 (const char *__restrict __nptr,
char **__restrict __endptr)
#if __HAVE_FLOAT32 && __GLIBC_USE (IEC_60559_TYPES_EXT)
extern _Float32 strtof32 (const char *__restrict __nptr,
char **__restrict __endptr)
#if __HAVE_FLOAT64 && __GLIBC_USE (IEC_60559_TYPES_EXT)
extern _Float64 strtof64 (const char *__restrict __nptr,
char **__restrict __endptr)
#if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
extern _Float128 strtof128 (const char *__restrict __nptr,
char **__restrict __endptr)
#if __HAVE_FLOAT32X && __GLIBC_USE (IEC_60559_TYPES_EXT)
extern _Float32x strtof32x (const char *__restrict __nptr,
char **__restrict __endptr)
#if __HAVE_FLOAT64X && __GLIBC_USE (IEC_60559_TYPES_EXT)
extern _Float64x strtof64x (const char *__restrict __nptr,
char **__restrict __endptr)
#if __HAVE_FLOAT128X && __GLIBC_USE (IEC_60559_TYPES_EXT)
extern _Float128x strtof128x (const char *__restrict __nptr,
char **__restrict __endptr)
/* Convert a string to a long integer. */
extern long int strtol (const char *__restrict __nptr,
char **__restrict __endptr, int __base)
/* Convert a string to an unsigned long integer. */
extern unsigned long int strtoul (const char *__restrict __nptr,
char **__restrict __endptr, int __base)
/* Convert a string to a quadword integer. */
extern long long int strtoq (const char *__restrict __nptr,
char **__restrict __endptr, int __base)
/* Convert a string to an unsigned quadword integer. */
extern unsigned long long int strtouq (const char *__restrict __nptr,
char **__restrict __endptr, int __base)
/* Convert a string to a quadword integer. */
extern long long int strtoll (const char *__restrict __nptr,
char **__restrict __endptr, int __base)
/* Convert a string to an unsigned quadword integer. */
extern unsigned long long int strtoull (const char *__restrict __nptr,
char **__restrict __endptr, int __base)
#endif /* ISO C99 or use MISC. */
/* Convert a floating-point number to a string. */
#if __GLIBC_USE (IEC_60559_BFP_EXT)
extern int strfromd (char *__dest, size_t __size, const char *__format,
extern int strfromf (char *__dest, size_t __size, const char *__format,
extern int strfroml (char *__dest, size_t __size, const char *__format,
#if __HAVE_FLOAT16 && __GLIBC_USE (IEC_60559_TYPES_EXT)
extern int strfromf16 (char *__dest, size_t __size, const char * __format,
#if __HAVE_FLOAT32 && __GLIBC_USE (IEC_60559_TYPES_EXT)
extern int strfromf32 (char *__dest, size_t __size, const char * __format,
#if __HAVE_FLOAT64 && __GLIBC_USE (IEC_60559_TYPES_EXT)
extern int strfromf64 (char *__dest, size_t __size, const char * __format,
#if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
extern int strfromf128 (char *__dest, size_t __size, const char * __format,
#if __HAVE_FLOAT32X && __GLIBC_USE (IEC_60559_TYPES_EXT)
extern int strfromf32x (char *__dest, size_t __size, const char * __format,
#if __HAVE_FLOAT64X && __GLIBC_USE (IEC_60559_TYPES_EXT)
extern int strfromf64x (char *__dest, size_t __size, const char * __format,
#if __HAVE_FLOAT128X && __GLIBC_USE (IEC_60559_TYPES_EXT)
extern int strfromf128x (char *__dest, size_t __size, const char * __format,
/* Parallel versions of the functions above which take the locale to
use as an additional parameter. These are GNU extensions inspired
by the POSIX.1-2008 extended locale API. */
# include <bits/types/locale_t.h>
extern long int strtol_l (const char *__restrict __nptr,
char **__restrict __endptr, int __base,
locale_t __loc) __THROW __nonnull ((1, 4));
extern unsigned long int strtoul_l (const char *__restrict __nptr,
char **__restrict __endptr,
int __base, locale_t __loc)
__THROW __nonnull ((1, 4));
extern long long int strtoll_l (const char *__restrict __nptr,
char **__restrict __endptr, int __base,
__THROW __nonnull ((1, 4));
extern unsigned long long int strtoull_l (const char *__restrict __nptr,
char **__restrict __endptr,
int __base, locale_t __loc)
__THROW __nonnull ((1, 4));
extern double strtod_l (const char *__restrict __nptr,
char **__restrict __endptr, locale_t __loc)
__THROW __nonnull ((1, 3));
extern float strtof_l (const char *__restrict __nptr,
char **__restrict __endptr, locale_t __loc)
__THROW __nonnull ((1, 3));
extern long double strtold_l (const char *__restrict __nptr,
char **__restrict __endptr,
__THROW __nonnull ((1, 3));
extern _Float16 strtof16_l (const char *__restrict __nptr,
char **__restrict __endptr,
__THROW __nonnull ((1, 3));
extern _Float32 strtof32_l (const char *__restrict __nptr,
char **__restrict __endptr,
__THROW __nonnull ((1, 3));
extern _Float64 strtof64_l (const char *__restrict __nptr,
char **__restrict __endptr,
__THROW __nonnull ((1, 3));
extern _Float128 strtof128_l (const char *__restrict __nptr,
char **__restrict __endptr,
__THROW __nonnull ((1, 3));
extern _Float32x strtof32x_l (const char *__restrict __nptr,
char **__restrict __endptr,
__THROW __nonnull ((1, 3));
extern _Float64x strtof64x_l (const char *__restrict __nptr,
char **__restrict __endptr,
__THROW __nonnull ((1, 3));
extern _Float128x strtof128x_l (const char *__restrict __nptr,
char **__restrict __endptr,
__THROW __nonnull ((1, 3));
#ifdef __USE_EXTERN_INLINES
__NTH (atoi (const char *__nptr))
return (int) strtol (__nptr, (char **) NULL, 10);
__NTH (atol (const char *__nptr))
return strtol (__nptr, (char **) NULL, 10);
__extension__ __extern_inline long long int
__NTH (atoll (const char *__nptr))
return strtoll (__nptr, (char **) NULL, 10);
#endif /* Optimizing and Inlining. */
#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
/* Convert N to base 64 using the digits "./0-9A-Za-z", least-significant
digit first. Returns a pointer to static storage overwritten by the
extern char *l64a (long int __n) __THROW __wur;
/* Read a number from a string S in base 64 as above. */
extern long int a64l (const char *__s)
__THROW __attribute_pure__ __nonnull ((1)) __wur;
#endif /* Use misc || extended X/Open. */
#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
# include <sys/types.h> /* we need int32_t... */
/* These are the functions that actually do things. The `random', `srandom',
`initstate' and `setstate' functions are those from BSD Unices.
The `rand' and `srand' functions are required by the ANSI standard.
We provide both interfaces to the same random number generator. */
/* Return a random long integer between 0 and RAND_MAX inclusive. */
extern long int random (void) __THROW;
/* Seed the random number generator with the given number. */
extern void srandom (unsigned int __seed) __THROW;
/* Initialize the random number generator to use state buffer STATEBUF,
of length STATELEN, and seed it with SEED. Optimal lengths are 8, 16,
32, 64, 128 and 256, the bigger the better; values less than 8 will
cause an error and values greater than 256 will be rounded down. */
extern char *initstate (unsigned int __seed, char *__statebuf,
size_t __statelen) __THROW __nonnull ((2));
/* Switch the random number generator to state buffer STATEBUF,
which should have been previously initialized by `initstate'. */
extern char *setstate (char *__statebuf) __THROW __nonnull ((1));
/* Reentrant versions of the `random' family of functions.
These functions all use the following data structure to contain
state, rather than global state variables. */
int32_t *fptr; /* Front pointer. */
int32_t *rptr; /* Rear pointer. */
int32_t *state; /* Array of state values. */
int rand_type; /* Type of random number generator. */
int rand_deg; /* Degree of random number generator. */
int rand_sep; /* Distance between front and rear. */
int32_t *end_ptr; /* Pointer behind state table. */
extern int random_r (struct random_data *__restrict __buf,
int32_t *__restrict __result) __THROW __nonnull ((1, 2));
extern int srandom_r (unsigned int __seed, struct random_data *__buf)
extern int initstate_r (unsigned int __seed, char *__restrict __statebuf,
struct random_data *__restrict __buf)
__THROW __nonnull ((2, 4));
extern int setstate_r (char *__restrict __statebuf,
struct random_data *__restrict __buf)
__THROW __nonnull ((1, 2));
#endif /* Use extended X/Open || misc. */
/* Return a random integer between 0 and RAND_MAX inclusive. */
extern int rand (void) __THROW;
/* Seed the random number generator with the given number. */
extern void srand (unsigned int __seed) __THROW;
/* Reentrant interface according to POSIX.1. */
extern int rand_r (unsigned int *__seed) __THROW;
#if defined __USE_MISC || defined __USE_XOPEN
/* System V style 48-bit random number generator functions. */
/* Return non-negative, double-precision floating-point value in [0.0,1.0). */
extern double drand48 (void) __THROW;
extern double erand48 (unsigned short int __xsubi[3]) __THROW __nonnull ((1));
/* Return non-negative, long integer in [0,2^31). */
extern long int lrand48 (void) __THROW;
extern long int nrand48 (unsigned short int __xsubi[3])
/* Return signed, long integers in [-2^31,2^31). */
extern long int mrand48 (void) __THROW;
extern long int jrand48 (unsigned short int __xsubi[3])
/* Seed random number generator. */
extern void srand48 (long int __seedval) __THROW;
extern unsigned short int *seed48 (unsigned short int __seed16v[3])
extern void lcong48 (unsigned short int __param[7]) __THROW __nonnull ((1));
/* Data structure for communication with thread safe versions. This
type is to be regarded as opaque. It's only exported because users
have to allocate objects of this type. */
unsigned short int __x[3]; /* Current state. */
unsigned short int __old_x[3]; /* Old state. */
unsigned short int __c; /* Additive const. in congruential formula. */
unsigned short int __init; /* Flag for initializing. */
__extension__ unsigned long long int __a; /* Factor in congruential
/* Return non-negative, double-precision floating-point value in [0.0,1.0). */