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