1/* Copyright (C) 1991-2007, 2009 Free Software Foundation, Inc. 2 This file is part of the GNU C Library. 3 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. 8 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. 13 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 17 02111-1307 USA. */ 18 19/* 20 * ISO C99 Standard: 7.20 General utilities <stdlib.h> 21 */ 22 23#ifndef _STDLIB_H 24 25#include <features.h> 26 27/* Get size_t, wchar_t and NULL from <stddef.h>. */ 28#define __need_size_t 29#ifndef __need_malloc_and_calloc 30# ifdef __UCLIBC_HAS_WCHAR__ 31# define __need_wchar_t 32# endif 33# define __need_NULL 34#endif 35#include <stddef.h> 36 37__BEGIN_DECLS 38 39#ifndef __need_malloc_and_calloc 40#define _STDLIB_H 1 41 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> 46 47# ifdef __USE_BSD 48 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. */ 51 52# if defined __GNUC__ && !defined __cplusplus 53# define __WAIT_INT(status) \ 54 (__extension__ (((union { __typeof(status) __in; int __i; }) \ 55 { .__in = (status) }).__i)) 56# else 57# define __WAIT_INT(status) (*(int *) &(status)) 58# endif 59 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. */ 64 65# if !defined __GNUC__ || __GNUC__ < 2 || defined __cplusplus 66# define __WAIT_STATUS void * 67# define __WAIT_STATUS_DEFN void * 68# else 69/* This works in GCC 2.6.1 and later. */ 70typedef union 71 { 72 union wait *__uptr; 73 int *__iptr; 74 } __WAIT_STATUS __attribute__ ((__transparent_union__)); 75# define __WAIT_STATUS_DEFN int * 76# endif 77 78# else /* Don't use BSD. */ 79 80# define __WAIT_INT(status) (status) 81# define __WAIT_STATUS int * 82# define __WAIT_STATUS_DEFN int * 83 84# endif /* Use BSD. */ 85 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)) 95# endif 96#endif /* X/Open and <sys/wait.h> not included. */ 97 98__BEGIN_NAMESPACE_STD 99/* Returned by `div'. */ 100typedef struct 101 { 102 int quot; /* Quotient. */ 103 int rem; /* Remainder. */ 104 } div_t; 105 106/* Returned by `ldiv'. */ 107#ifndef __ldiv_t_defined 108typedef struct 109 { 110 long int quot; /* Quotient. */ 111 long int rem; /* Remainder. */ 112 } ldiv_t; 113# define __ldiv_t_defined 1 114#endif 115__END_NAMESPACE_STD 116 117#if defined __USE_ISOC99 && !defined __lldiv_t_defined 118__BEGIN_NAMESPACE_C99 119/* Returned by `lldiv'. */ 120__extension__ typedef struct 121 { 122 long long int quot; /* Quotient. */ 123 long long int rem; /* Remainder. */ 124 } lldiv_t; 125# define __lldiv_t_defined 1 126__END_NAMESPACE_C99 127#endif 128 129 130/* The largest number rand will return (same as INT_MAX). */ 131#define RAND_MAX 2147483647 132 133 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. */ 138 139 140/* Maximum length of a multibyte character in the current locale. */ 141#if 0 142#define MB_CUR_MAX (__ctype_get_mb_cur_max ()) 143extern size_t __ctype_get_mb_cur_max (void) __THROW __wur; 144#else 145#ifdef __UCLIBC_HAS_WCHAR__ 146# define MB_CUR_MAX (_stdlib_mb_cur_max ()) 147extern size_t _stdlib_mb_cur_max (void) __THROW __wur; 148#else 149# define MB_CUR_MAX 1 150#endif 151#endif 152 153 154__BEGIN_NAMESPACE_STD 155#ifdef __UCLIBC_HAS_FLOATS__ 156/* Convert a string to a floating-point number. */ 157extern double atof (__const char *__nptr) 158 __THROW __attribute_pure__ __nonnull ((1)) __wur; 159#endif /* __UCLIBC_HAS_FLOATS__ */ 160/* Convert a string to an integer. */ 161extern int atoi (__const char *__nptr) 162 __THROW __attribute_pure__ __nonnull ((1)) __wur; 163/* Convert a string to a long integer. */ 164extern long int atol (__const char *__nptr) 165 __THROW __attribute_pure__ __nonnull ((1)) __wur; 166__END_NAMESPACE_STD 167 168#if defined __USE_ISOC99 || defined __USE_MISC 169__BEGIN_NAMESPACE_C99 170/* Convert a string to a long long integer. */ 171__extension__ extern long long int atoll (__const char *__nptr) 172 __THROW __attribute_pure__ __nonnull ((1)) __wur; 173__END_NAMESPACE_C99 174#endif 175 176#ifdef __UCLIBC_HAS_FLOATS__ 177__BEGIN_NAMESPACE_STD 178/* Convert a string to a floating-point number. */ 179extern double strtod (__const char *__restrict __nptr, 180 char **__restrict __endptr) 181 __THROW __nonnull ((1)) __wur; 182__END_NAMESPACE_STD 183 184#ifdef __USE_ISOC99 185__BEGIN_NAMESPACE_C99 186/* Likewise for `float' and `long double' sizes of floating-point numbers. */ 187extern float strtof (__const char *__restrict __nptr, 188 char **__restrict __endptr) __THROW __nonnull ((1)) __wur; 189 190extern long double strtold (__const char *__restrict __nptr, 191 char **__restrict __endptr) 192 __THROW __nonnull ((1)) __wur; 193__END_NAMESPACE_C99 194#endif 195#endif /* __UCLIBC_HAS_FLOATS__ */ 196 197__BEGIN_NAMESPACE_STD 198/* Convert a string to a long integer. */ 199extern long int strtol (__const char *__restrict __nptr, 200 char **__restrict __endptr, int __base) 201 __THROW __nonnull ((1)) __wur; 202/* Convert a string to an unsigned long integer. */ 203extern unsigned long int strtoul (__const char *__restrict __nptr, 204 char **__restrict __endptr, int __base) 205 __THROW __nonnull ((1)) __wur; 206__END_NAMESPACE_STD 207 208#ifdef __USE_BSD 209#include <sys/types.h> /* for u_quad_t */ 210 211/* Convert a string to a quadword integer. */ 212__extension__ 213extern quad_t strtoq (__const char *__restrict __nptr, 214 char **__restrict __endptr, int __base) 215 __THROW __nonnull ((1)) __wur; 216/* Convert a string to an unsigned quadword integer. */ 217__extension__ 218extern u_quad_t strtouq (__const char *__restrict __nptr, 219 char **__restrict __endptr, int __base) 220 __THROW __nonnull ((1)) __wur; 221#endif /* GCC and use BSD. */ 222 223#if defined __USE_ISOC99 || defined __USE_MISC 224__BEGIN_NAMESPACE_C99 225/* Convert a string to a quadword integer. */ 226__extension__ 227extern long long int strtoll (__const char *__restrict __nptr, 228 char **__restrict __endptr, int __base) 229 __THROW __nonnull ((1)) __wur; 230/* Convert a string to an unsigned quadword integer. */ 231__extension__ 232extern unsigned long long int strtoull (__const char *__restrict __nptr, 233 char **__restrict __endptr, int __base) 234 __THROW __nonnull ((1)) __wur; 235__END_NAMESPACE_C99 236#endif /* ISO C99 or GCC and use MISC. */ 237 238 239#if defined __USE_GNU && defined __UCLIBC_HAS_XLOCALE__ 240/* The concept of one static locale per category is not very well 241 thought out. Many applications will need to process its data using 242 information from several different locales. Another problem is 243 the implementation of the internationalization handling in the 244 ISO C++ standard library. To support this another set of 245 the functions using locale data exist which take an additional 246 argument. 247 248 Attention: even though several *_l interfaces are part of POSIX:2008, 249 these are not. */ 250 251/* Structure for reentrant locale using functions. This is an 252 (almost) opaque type for the user level programs. */ 253# include <xlocale.h> 254 255/* Special versions of the functions above which take the locale to 256 use as an additional parameter. */ 257extern long int strtol_l (__const char *__restrict __nptr, 258 char **__restrict __endptr, int __base, 259 __locale_t __loc) __THROW __nonnull ((1, 4)) __wur; 260 261extern unsigned long int strtoul_l (__const char *__restrict __nptr, 262 char **__restrict __endptr, 263 int __base, __locale_t __loc) 264 __THROW __nonnull ((1, 4)) __wur; 265 266__extension__ 267extern long long int strtoll_l (__const char *__restrict __nptr, 268 char **__restrict __endptr, int __base, 269 __locale_t __loc) 270 __THROW __nonnull ((1, 4)) __wur; 271 272__extension__ 273extern unsigned long long int strtoull_l (__const char *__restrict __nptr, 274 char **__restrict __endptr, 275 int __base, __locale_t __loc) 276 __THROW __nonnull ((1, 4)) __wur; 277 278#ifdef __UCLIBC_HAS_FLOATS__ 279extern double strtod_l (__const char *__restrict __nptr, 280 char **__restrict __endptr, __locale_t __loc) 281 __THROW __nonnull ((1, 3)) __wur; 282 283extern float strtof_l (__const char *__restrict __nptr, 284 char **__restrict __endptr, __locale_t __loc) 285 __THROW __nonnull ((1, 3)) __wur; 286 287extern long double strtold_l (__const char *__restrict __nptr, 288 char **__restrict __endptr, 289 __locale_t __loc) 290 __THROW __nonnull ((1, 3)) __wur; 291#endif /* __UCLIBC_HAS_FLOATS__ */ 292#endif /* GNU */ 293 294 295#if defined __USE_SVID || defined __USE_XOPEN_EXTENDED 296/* Convert N to base 64 using the digits "./0-9A-Za-z", least-significant 297 digit first. Returns a pointer to static storage overwritten by the 298 next call. */ 299extern char *l64a (long int __n) __THROW __wur; 300 301/* Read a number from a string S in base 64 as above. */ 302extern long int a64l (__const char *__s) 303 __THROW __attribute_pure__ __nonnull ((1)) __wur; 304 305#endif /* Use SVID || extended X/Open. */ 306 307#if defined __USE_SVID || defined __USE_XOPEN_EXTENDED || defined __USE_BSD 308# include <sys/types.h> /* we need int32_t... */ 309 310/* These are the functions that actually do things. The `random', `srandom', 311 `initstate' and `setstate' functions are those from BSD Unices. 312 The `rand' and `srand' functions are required by the ANSI standard. 313 We provide both interfaces to the same random number generator. */ 314/* Return a random long integer between 0 and RAND_MAX inclusive. */ 315extern long int random (void) __THROW; 316 317/* Seed the random number generator with the given number. */ 318extern void srandom (unsigned int __seed) __THROW; 319 320/* Initialize the random number generator to use state buffer STATEBUF, 321 of length STATELEN, and seed it with SEED. Optimal lengths are 8, 16, 322 32, 64, 128 and 256, the bigger the better; values less than 8 will 323 cause an error and values greater than 256 will be rounded down. */ 324extern char *initstate (unsigned int __seed, char *__statebuf, 325 size_t __statelen) __THROW __nonnull ((2)); 326 327/* Switch the random number generator to state buffer STATEBUF, 328 which should have been previously initialized by `initstate'. */ 329extern char *setstate (char *__statebuf) __THROW __nonnull ((1)); 330 331 332# ifdef __USE_MISC 333/* Reentrant versions of the `random' family of functions. 334 These functions all use the following data structure to contain 335 state, rather than global state variables. */ 336 337struct random_data 338 { 339 int32_t *fptr; /* Front pointer. */ 340 int32_t *rptr; /* Rear pointer. */ 341 int32_t *state; /* Array of state values. */ 342#if 0 343 int rand_type; /* Type of random number generator. */ 344 int rand_deg; /* Degree of random number generator. */ 345 int rand_sep; /* Distance between front and rear. */ 346#else 347 /* random_r.c, TYPE_x, DEG_x, SEP_x - small enough for int8_t */ 348 int8_t rand_type; /* Type of random number generator. */ 349 int8_t rand_deg; /* Degree of random number generator. */ 350 int8_t rand_sep; /* Distance between front and rear. */ 351#endif 352 int32_t *end_ptr; /* Pointer behind state table. */ 353 }; 354 355extern int random_r (struct random_data *__restrict __buf, 356 int32_t *__restrict __result) __THROW __nonnull ((1, 2)); 357 358extern int srandom_r (unsigned int __seed, struct random_data *__buf) 359 __THROW __nonnull ((2)); 360 361extern int initstate_r (unsigned int __seed, char *__restrict __statebuf, 362 size_t __statelen, 363 struct random_data *__restrict __buf) 364 __THROW __nonnull ((2, 4)); 365 366extern int setstate_r (char *__restrict __statebuf, 367 struct random_data *__restrict __buf) 368 __THROW __nonnull ((1, 2)); 369# endif /* Use misc. */ 370#endif /* Use SVID || extended X/Open || BSD. */ 371 372 373__BEGIN_NAMESPACE_STD 374/* Return a random integer between 0 and RAND_MAX inclusive. */ 375extern int rand (void) __THROW; 376/* Seed the random number generator with the given number. */ 377extern void srand (unsigned int __seed) __THROW; 378__END_NAMESPACE_STD 379 380#ifdef __USE_POSIX 381/* Reentrant interface according to POSIX.1. */ 382extern int rand_r (unsigned int *__seed) __THROW; 383#endif 384 385 386#if defined __USE_SVID || defined __USE_XOPEN 387/* System V style 48-bit random number generator functions. */ 388 389#ifdef __UCLIBC_HAS_FLOATS__ 390/* Return non-negative, double-precision floating-point value in [0.0,1.0). */ 391extern double drand48 (void) __THROW; 392extern double erand48 (unsigned short int __xsubi[3]) __THROW __nonnull ((1)); 393#endif /* __UCLIBC_HAS_FLOATS__ */ 394 395/* Return non-negative, long integer in [0,2^31). */ 396extern long int lrand48 (void) __THROW; 397extern long int nrand48 (unsigned short int __xsubi[3]) 398 __THROW __nonnull ((1)); 399 400/* Return signed, long integers in [-2^31,2^31). */ 401extern long int mrand48 (void) __THROW; 402extern long int jrand48 (unsigned short int __xsubi[3]) 403 __THROW __nonnull ((1)); 404 405/* Seed random number generator. */ 406extern void srand48 (long int __seedval) __THROW; 407extern unsigned short int *seed48 (unsigned short int __seed16v[3]) 408 __THROW __nonnull ((1)); 409extern void lcong48 (unsigned short int __param[7]) __THROW __nonnull ((1)); 410 411# ifdef __USE_MISC 412/* Data structure for communication with thread safe versions. This 413 type is to be regarded as opaque. It's only exported because users 414 have to allocate objects of this type. */ 415struct drand48_data 416 { 417 unsigned short int __x[3]; /* Current state. */ 418 unsigned short int __old_x[3]; /* Old state. */ 419 unsigned short int __c; /* Additive const. in congruential formula. */ 420 unsigned short int __init; /* Flag for initializing. */ 421 unsigned long long int __a; /* Factor in congruential formula. */ 422 }; 423 424#ifdef __UCLIBC_HAS_FLOATS__ 425/* Return non-negative, double-precision floating-point value in [0.0,1.0). */ 426extern int drand48_r (struct drand48_data *__restrict __buffer, 427 double *__restrict __result) __THROW __nonnull ((1, 2)); 428extern int erand48_r (unsigned short int __xsubi[3], 429 struct drand48_data *__restrict __buffer, 430 double *__restrict __result) __THROW __nonnull ((1, 2)); 431#endif /* __UCLIBC_HAS_FLOATS__ */ 432 433/* Return non-negative, long integer in [0,2^31). */ 434extern int lrand48_r (struct drand48_data *__restrict __buffer, 435 long int *__restrict __result) 436 __THROW __nonnull ((1, 2)); 437extern int nrand48_r (unsigned short int __xsubi[3], 438 struct drand48_data *__restrict __buffer, 439 long int *__restrict __result) 440 __THROW __nonnull ((1, 2)); 441 442/* Return signed, long integers in [-2^31,2^31). */ 443extern int mrand48_r (struct drand48_data *__restrict __buffer, 444 long int *__restrict __result) 445 __THROW __nonnull ((1, 2)); 446extern int jrand48_r (unsigned short int __xsubi[3], 447 struct drand48_data *__restrict __buffer, 448 long int *__restrict __result) 449 __THROW __nonnull ((1, 2)); 450 451/* Seed random number generator. */ 452extern int srand48_r (long int __seedval, struct drand48_data *__buffer) 453 __THROW __nonnull ((2)); 454 455extern int seed48_r (unsigned short int __seed16v[3], 456 struct drand48_data *__buffer) __THROW __nonnull ((1, 2)); 457 458extern int lcong48_r (unsigned short int __param[7], 459 struct drand48_data *__buffer) 460 __THROW __nonnull ((1, 2)); 461# endif /* Use misc. */ 462#endif /* Use SVID or X/Open. */ 463 464#endif /* don't just need malloc and calloc */ 465 466#ifndef __malloc_and_calloc_defined 467# define __malloc_and_calloc_defined 468__BEGIN_NAMESPACE_STD 469/* Allocate SIZE bytes of memory. */ 470extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur; 471/* We want the malloc symbols overridable at runtime 472 * libc_hidden_proto(malloc) */ 473/* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */ 474extern void *calloc (size_t __nmemb, size_t __size) 475 __THROW __attribute_malloc__ __wur; 476__END_NAMESPACE_STD 477#endif 478 479#ifndef __need_malloc_and_calloc 480__BEGIN_NAMESPACE_STD 481/* Re-allocate the previously allocated block 482 in PTR, making the new block SIZE bytes long. */ 483/* __attribute_malloc__ is not used, because if realloc returns 484 the same pointer that was passed to it, aliasing needs to be allowed 485 between objects pointed by the old and new pointers. */ 486extern void *realloc (void *__ptr, size_t __size) 487 __THROW __attribute_warn_unused_result__; 488/* Free a block allocated by `malloc', `realloc' or `calloc'. */ 489extern void free (void *__ptr) __THROW; 490__END_NAMESPACE_STD 491 492#if 0 /*def __USE_MISC*/ 493/* Free a block. An alias for `free'. (Sun Unices). */ 494extern void cfree (void *__ptr) __THROW; 495#endif /* Use misc. */ 496 497#if defined __USE_GNU || defined __USE_BSD || defined __USE_MISC 498# include <alloca.h> 499#endif /* Use GNU, BSD, or misc. */ 500 501#if defined __USE_BSD || defined __USE_XOPEN_EXTENDED 502/* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */ 503extern void *valloc (size_t __size) __THROW __attribute_malloc__ __wur; 504#endif 505 506#if defined __USE_XOPEN2K && defined __UCLIBC_HAS_ADVANCED_REALTIME__ 507/* Allocate memory of SIZE bytes with an alignment of ALIGNMENT. */ 508extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size) 509 __THROW __nonnull ((1)) __wur; 510#endif 511 512__BEGIN_NAMESPACE_STD 513/* Abort execution and generate a core-dump. */ 514extern void abort (void) __THROW __attribute__ ((__noreturn__)); 515 516 517/* Register a function to be called when `exit' is called. */ 518extern int atexit (void (*__func) (void)) __THROW __nonnull ((1)); 519__END_NAMESPACE_STD 520 521#ifdef __USE_MISC 522/* Register a function to be called with the status 523 given to `exit' and the given argument. */ 524extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg) 525 __THROW __nonnull ((1)); 526#endif 527 528__BEGIN_NAMESPACE_STD 529/* Call all functions registered with `atexit' and `on_exit', 530 in the reverse of the order in which they were registered, 531 perform stdio cleanup, and terminate program execution with STATUS. */ 532extern void exit (int __status) __THROW __attribute__ ((__noreturn__)); 533__END_NAMESPACE_STD 534 535#ifdef __USE_ISOC99 536__BEGIN_NAMESPACE_C99 537/* Terminate the program with STATUS without calling any of the 538 functions registered with `atexit' or `on_exit'. */ 539extern void _Exit (int __status) __THROW __attribute__ ((__noreturn__)); 540__END_NAMESPACE_C99 541#endif 542 543 544__BEGIN_NAMESPACE_STD 545/* Return the value of envariable NAME, or NULL if it doesn't exist. */ 546extern char *getenv (__const char *__name) __THROW __nonnull ((1)) __wur; 547__END_NAMESPACE_STD 548 549#if 0 550/* This function is similar to the above but returns NULL if the 551 programs is running with SUID or SGID enabled. */ 552extern char *__secure_getenv (__const char *__name) 553 __THROW __nonnull ((1)) __wur; 554#endif 555 556#if defined __USE_SVID || defined __USE_XOPEN 557/* The SVID says this is in <stdio.h>, but this seems a better place. */ 558/* Put STRING, which is of the form "NAME=VALUE", in the environment. 559 If there is no `=', remove NAME from the environment. */ 560extern int putenv (char *__string) __THROW __nonnull ((1)); 561#endif 562 563#if defined __USE_BSD || defined __USE_XOPEN2K 564/* Set NAME to VALUE in the environment. 565 If REPLACE is nonzero, overwrite an existing value. */ 566extern int setenv (__const char *__name, __const char *__value, int __replace) 567 __THROW __nonnull ((2)); 568 569/* Remove the variable NAME from the environment. */ 570extern int unsetenv (__const char *__name) __THROW; 571#endif 572 573/* The following is used by uClibc in atexit.c and sysconf.c */ 574/* We have no limit when __UCLIBC_DYNAMIC_ATEXIT__ is enabled. */ 575#ifdef __UCLIBC_DYNAMIC_ATEXIT__ 576# define __UCLIBC_MAX_ATEXIT INT_MAX 577#else 578# define __UCLIBC_MAX_ATEXIT 20 579#endif 580 581 582#ifdef __USE_MISC 583/* The `clearenv' was planned to be added to POSIX.1 but probably 584 never made it. Nevertheless the POSIX.9 standard (POSIX bindings 585 for Fortran 77) requires this function. */ 586extern int clearenv (void) __THROW; 587#endif 588 589 590#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED 591# if defined __UCLIBC_SUSV3_LEGACY__ 592/* Generate a unique temporary file name from TEMPLATE. 593 The last six characters of TEMPLATE must be "XXXXXX"; 594 they are replaced with a string that makes the file name unique. 595 Returns TEMPLATE, or a null pointer if it cannot get a unique file name. */ 596extern char *mktemp (char *__template) __THROW __nonnull ((1)) __wur; 597# endif 598 599/* Generate a unique temporary file name from TEMPLATE. 600 The last six characters of TEMPLATE must be "XXXXXX"; 601 they are replaced with a string that makes the filename unique. 602 Returns a file descriptor open on the file for reading and writing, 603 or -1 if it cannot create a uniquely-named file. 604 605 This function is a possible cancellation point and therefore not 606 marked with __THROW. */ 607# ifndef __USE_FILE_OFFSET64 608extern int mkstemp (char *__template) __nonnull ((1)) __wur; 609# else 610# ifdef __REDIRECT 611extern int __REDIRECT (mkstemp, (char *__template), mkstemp64) 612 __nonnull ((1)) __wur; 613# else 614# define mkstemp mkstemp64 615# endif 616# endif 617# ifdef __USE_LARGEFILE64 618extern int mkstemp64 (char *__template) __nonnull ((1)) __wur; 619# endif 620#endif 621 622#if defined __USE_BSD || defined __USE_XOPEN2K8 623/* Create a unique temporary directory from TEMPLATE. 624 The last six characters of TEMPLATE must be "XXXXXX"; 625 they are replaced with a string that makes the directory name unique. 626 Returns TEMPLATE, or a null pointer if it cannot get a unique name. 627 The directory is created mode 700. */ 628extern char *mkdtemp (char *__template) __THROW __nonnull ((1)) __wur; 629#endif 630 631 632__BEGIN_NAMESPACE_STD 633/* Execute the given line as a shell command. 634 635 This function is a cancellation point and therefore not marked with 636 __THROW. */ 637extern int system (__const char *__command) __wur; 638__END_NAMESPACE_STD 639 640 641#ifdef __USE_GNU 642/* Return a malloc'd string containing the canonical absolute name of the 643 existing named file. */ 644extern char *canonicalize_file_name (__const char *__name) 645 __THROW __nonnull ((1)) __wur; 646#endif 647 648#if defined __USE_BSD || defined __USE_XOPEN_EXTENDED 649/* Return the canonical absolute name of file NAME. If RESOLVED is 650 null, the result is malloc'd; otherwise, if the canonical name is 651 PATH_MAX chars or more, returns null with `errno' set to 652 ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, 653 returns the name in RESOLVED. */ 654extern char *realpath (__const char *__restrict __name, 655 char *__restrict __resolved) __THROW __wur; 656#endif 657 658 659/* Shorthand for type of comparison functions. */ 660#ifndef __COMPAR_FN_T 661# define __COMPAR_FN_T 662typedef int (*__compar_fn_t) (__const void *, __const void *); 663 664# ifdef __USE_GNU 665typedef __compar_fn_t comparison_fn_t; 666# endif 667#endif 668 669__BEGIN_NAMESPACE_STD 670/* Do a binary search for KEY in BASE, which consists of NMEMB elements 671 of SIZE bytes each, using COMPAR to perform the comparisons. */ 672extern void *bsearch (__const void *__key, __const void *__base, 673 size_t __nmemb, size_t __size, __compar_fn_t __compar) 674 __nonnull ((1, 2, 5)) __wur; 675 676/* Sort NMEMB elements of BASE, of SIZE bytes each, 677 using COMPAR to perform the comparisons. */ 678extern void qsort (void *__base, size_t __nmemb, size_t __size, 679 __compar_fn_t __compar) __nonnull ((1, 4)); 680 681 682/* Return the absolute value of X. */ 683extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur; 684extern long int labs (long int __x) __THROW __attribute__ ((__const__)) __wur; 685__END_NAMESPACE_STD 686 687#ifdef __USE_ISOC99 688__extension__ extern long long int llabs (long long int __x) 689 __THROW __attribute__ ((__const__)) __wur; 690#endif 691 692 693__BEGIN_NAMESPACE_STD 694/* Return the `div_t', `ldiv_t' or `lldiv_t' representation 695 of the value of NUMER over DENOM. */ 696/* GCC may have built-ins for these someday. */ 697extern div_t div (int __numer, int __denom) 698 __THROW __attribute__ ((__const__)) __wur; 699extern ldiv_t ldiv (long int __numer, long int __denom) 700 __THROW __attribute__ ((__const__)) __wur; 701__END_NAMESPACE_STD 702 703#ifdef __USE_ISOC99 704__BEGIN_NAMESPACE_C99 705__extension__ extern lldiv_t lldiv (long long int __numer, 706 long long int __denom) 707 __THROW __attribute__ ((__const__)) __wur; 708__END_NAMESPACE_C99 709#endif 710 711 712#if ( defined __USE_SVID || defined __USE_XOPEN_EXTENDED ) && defined __UCLIBC_HAS_FLOATS__ 713/* Convert floating point numbers to strings. The returned values are 714 valid only until another call to the same function. */ 715 716# ifdef __UCLIBC_SUSV3_LEGACY__ 717#if 0 718/* Convert VALUE to a string with NDIGIT digits and return a pointer to 719 this. Set *DECPT with the position of the decimal character and *SIGN 720 with the sign of the number. */ 721extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt, 722 int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur; 723 724/* Convert VALUE to a string rounded to NDIGIT decimal digits. Set *DECPT 725 with the position of the decimal character and *SIGN with the sign of 726 the number. */ 727extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt, 728 int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur; 729#endif 730 731/* If possible convert VALUE to a string with NDIGIT significant digits. 732 Otherwise use exponential representation. The resulting string will 733 be written to BUF. */ 734extern char *gcvt (double __value, int __ndigit, char *__buf) 735 __THROW __nonnull ((3)) __wur; 736# endif /* __UCLIBC_SUSV3_LEGACY__ */ 737 738 739# if 0 /*def __USE_MISC*/ 740/* Long double versions of above functions. */ 741extern char *qecvt (long double __value, int __ndigit, 742 int *__restrict __decpt, int *__restrict __sign) 743 __THROW __nonnull ((3, 4)) __wur; 744extern char *qfcvt (long double __value, int __ndigit, 745 int *__restrict __decpt, int *__restrict __sign) 746 __THROW __nonnull ((3, 4)) __wur; 747extern char *qgcvt (long double __value, int __ndigit, char *__buf) 748 __THROW __nonnull ((3)) __wur; 749 750 751/* Reentrant version of the functions above which provide their own 752 buffers. */ 753extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt, 754 int *__restrict __sign, char *__restrict __buf, 755 size_t __len) __THROW __nonnull ((3, 4, 5)); 756extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt, 757 int *__restrict __sign, char *__restrict __buf, 758 size_t __len) __THROW __nonnull ((3, 4, 5)); 759 760extern int qecvt_r (long double __value, int __ndigit, 761 int *__restrict __decpt, int *__restrict __sign, 762 char *__restrict __buf, size_t __len) 763 __THROW __nonnull ((3, 4, 5)); 764extern int qfcvt_r (long double __value, int __ndigit, 765 int *__restrict __decpt, int *__restrict __sign, 766 char *__restrict __buf, size_t __len) 767 __THROW __nonnull ((3, 4, 5)); 768# endif /* misc */ 769#endif /* use MISC || use X/Open Unix */ 770 771 772#ifdef __UCLIBC_HAS_WCHAR__ 773__BEGIN_NAMESPACE_STD 774/* Return the length of the multibyte character 775 in S, which is no longer than N. */ 776extern int mblen (__const char *__s, size_t __n) __THROW __wur; 777/* Return the length of the given multibyte character, 778 putting its `wchar_t' representation in *PWC. */ 779extern int mbtowc (wchar_t *__restrict __pwc, 780 __const char *__restrict __s, size_t __n) __THROW __wur; 781/* Put the multibyte character represented 782 by WCHAR in S, returning its length. */ 783extern int wctomb (char *__s, wchar_t __wchar) __THROW __wur; 784 785 786/* Convert a multibyte string to a wide char string. */ 787extern size_t mbstowcs (wchar_t *__restrict __pwcs, 788 __const char *__restrict __s, size_t __n) __THROW; 789/* Convert a wide char string to multibyte string. */ 790extern size_t wcstombs (char *__restrict __s, 791 __const wchar_t *__restrict __pwcs, size_t __n) 792 __THROW; 793__END_NAMESPACE_STD 794#endif /* __UCLIBC_HAS_WCHAR__ */ 795 796 797#if 0 /*def __USE_SVID*/ 798/* Determine whether the string value of RESPONSE matches the affirmation 799 or negative response expression as specified by the LC_MESSAGES category 800 in the program's current locale. Returns 1 if affirmative, 0 if 801 negative, and -1 if not matching. */ 802extern int rpmatch (__const char *__response) __THROW __nonnull ((1)) __wur; 803#endif 804 805 806#ifdef __USE_XOPEN_EXTENDED 807/* Parse comma separated suboption from *OPTIONP and match against 808 strings in TOKENS. If found return index and set *VALUEP to 809 optional value introduced by an equal sign. If the suboption is 810 not part of TOKENS return in *VALUEP beginning of unknown 811 suboption. On exit *OPTIONP is set to the beginning of the next 812 token or at the terminating NUL character. */ 813extern int getsubopt (char **__restrict __optionp, 814 char *__const *__restrict __tokens, 815 char **__restrict __valuep) 816 __THROW __nonnull ((1, 2, 3)) __wur; 817#endif 818 819 820#ifdef __USE_XOPEN 821# if defined __UCLIBC_HAS_CRYPT__ 822/* Setup DES tables according KEY. */ 823extern void setkey (__const char *__key) __THROW __nonnull ((1)); 824# endif /* __UCLIBC_HAS_CRYPT__ */ 825#endif 826 827 828/* X/Open pseudo terminal handling. */ 829 830#ifdef __USE_XOPEN2K 831/* Return a master pseudo-terminal handle. */ 832extern int posix_openpt (int __oflag) __wur; 833#endif 834 835#ifdef __USE_XOPEN 836/* The next four functions all take a master pseudo-tty fd and 837 perform an operation on the associated slave: */ 838 839#ifdef __UCLIBC_HAS_PTY__ 840/* Chown the slave to the calling user. */ 841extern int grantpt (int __fd) __THROW; 842 843/* Release an internal lock so the slave can be opened. 844 Call after grantpt(). */ 845extern int unlockpt (int __fd) __THROW; 846 847/* Return the pathname of the pseudo terminal slave assoicated with 848 the master FD is open on, or NULL on errors. 849 The returned storage is good until the next call to this function. */ 850extern char *ptsname (int __fd) __THROW __wur; 851#endif /* __UCLIBC_HAS_PTY__ */ 852#endif 853 854#ifdef __USE_GNU 855# if defined __UCLIBC_HAS_PTY__ 856/* Store at most BUFLEN characters of the pathname of the slave pseudo 857 terminal associated with the master FD is open on in BUF. 858 Return 0 on success, otherwise an error number. */ 859extern int ptsname_r (int __fd, char *__buf, size_t __buflen) 860 __THROW __nonnull ((2)); 861# endif 862# if defined __UCLIBC_HAS_GETPT__ 863/* Open a master pseudo terminal and return its file descriptor. */ 864extern int getpt (void); 865# endif 866#endif 867 868#if 0 /* def __USE_BSD */ 869/* Put the 1 minute, 5 minute and 15 minute load averages into the first 870 NELEM elements of LOADAVG. Return the number written (never more than 871 three, but may be less than NELEM), or -1 if an error occurred. */ 872extern int getloadavg (double __loadavg[], int __nelem) 873 __THROW __nonnull ((1)); 874#endif 875 876#ifdef __UCLIBC_HAS_ARC4RANDOM__ 877#include <stdint.h> 878extern uint32_t arc4random(void); 879extern void arc4random_stir(void); 880extern void arc4random_addrandom(unsigned char *, int); 881#endif 882 883 884#endif /* don't just need malloc and calloc */ 885#undef __need_malloc_and_calloc 886 887__END_DECLS 888 889#endif /* stdlib.h */ 890