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