]> git.ipfire.org Git - thirdparty/glibc.git/blame - stdlib/stdlib.h
Fix cmpli usage in power6 memset.
[thirdparty/glibc.git] / stdlib / stdlib.h
CommitLineData
f7a9f785 1/* Copyright (C) 1991-2016 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
9323b58f 44/* Define the macros <sys/wait.h> also would define this way. */
b49ab5f4
FW
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)
a044c713 51# ifdef __WIFCONTINUED
b49ab5f4 52# define WIFCONTINUED(status) __WIFCONTINUED (status)
a044c713 53# endif
f095bb72 54#endif /* X/Open or XPG7 and <sys/wait.h> not included. */
9323b58f 55
7a5affeb 56__BEGIN_NAMESPACE_STD
28f540f4
RM
57/* Returned by `div'. */
58typedef struct
59 {
60 int quot; /* Quotient. */
61 int rem; /* Remainder. */
62 } div_t;
63
64/* Returned by `ldiv'. */
e518937a 65#ifndef __ldiv_t_defined
28f540f4
RM
66typedef struct
67 {
68 long int quot; /* Quotient. */
69 long int rem; /* Remainder. */
70 } ldiv_t;
e518937a
UD
71# define __ldiv_t_defined 1
72#endif
7a5affeb 73__END_NAMESPACE_STD
28f540f4 74
ec751a23 75#if defined __USE_ISOC99 && !defined __lldiv_t_defined
7a5affeb 76__BEGIN_NAMESPACE_C99
59dd8641 77/* Returned by `lldiv'. */
7782d0bf 78__extension__ typedef struct
59dd8641
RM
79 {
80 long long int quot; /* Quotient. */
81 long long int rem; /* Remainder. */
82 } lldiv_t;
e518937a 83# define __lldiv_t_defined 1
7a5affeb 84__END_NAMESPACE_C99
59dd8641
RM
85#endif
86
28f540f4
RM
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
0200214b
RM
98/* Maximum length of a multibyte character in the current locale. */
99#define MB_CUR_MAX (__ctype_get_mb_cur_max ())
0476597b 100extern size_t __ctype_get_mb_cur_max (void) __THROW __wur;
28f540f4
RM
101
102
7a5affeb 103__BEGIN_NAMESPACE_STD
28f540f4 104/* Convert a string to a floating-point number. */
a784e502 105extern double atof (const char *__nptr)
0476597b 106 __THROW __attribute_pure__ __nonnull ((1)) __wur;
28f540f4 107/* Convert a string to an integer. */
a784e502 108extern int atoi (const char *__nptr)
0476597b 109 __THROW __attribute_pure__ __nonnull ((1)) __wur;
28f540f4 110/* Convert a string to a long integer. */
a784e502 111extern long int atol (const char *__nptr)
0476597b 112 __THROW __attribute_pure__ __nonnull ((1)) __wur;
7a5affeb 113__END_NAMESPACE_STD
28f540f4 114
acd7f096 115#ifdef __USE_ISOC99
7a5affeb 116__BEGIN_NAMESPACE_C99
fb4dfa0c 117/* Convert a string to a long long integer. */
a784e502 118__extension__ extern long long int atoll (const char *__nptr)
0476597b 119 __THROW __attribute_pure__ __nonnull ((1)) __wur;
7a5affeb 120__END_NAMESPACE_C99
7cc27f44
UD
121#endif
122
7a5affeb 123__BEGIN_NAMESPACE_STD
28f540f4 124/* Convert a string to a floating-point number. */
a784e502 125extern double strtod (const char *__restrict __nptr,
0476597b 126 char **__restrict __endptr)
c0baea34 127 __THROW __nonnull ((1));
7a5affeb 128__END_NAMESPACE_STD
28f540f4 129
ec751a23 130#ifdef __USE_ISOC99
7a5affeb 131__BEGIN_NAMESPACE_C99
28f540f4 132/* Likewise for `float' and `long double' sizes of floating-point numbers. */
a784e502 133extern float strtof (const char *__restrict __nptr,
c0baea34 134 char **__restrict __endptr) __THROW __nonnull ((1));
2f6d1f1b 135
a784e502 136extern long double strtold (const char *__restrict __nptr,
be27d08c 137 char **__restrict __endptr)
c0baea34 138 __THROW __nonnull ((1));
7a5affeb 139__END_NAMESPACE_C99
28f540f4
RM
140#endif
141
7a5affeb 142__BEGIN_NAMESPACE_STD
28f540f4 143/* Convert a string to a long integer. */
a784e502 144extern long int strtol (const char *__restrict __nptr,
be27d08c 145 char **__restrict __endptr, int __base)
c0baea34 146 __THROW __nonnull ((1));
28f540f4 147/* Convert a string to an unsigned long integer. */
a784e502 148extern unsigned long int strtoul (const char *__restrict __nptr,
c1422e5b 149 char **__restrict __endptr, int __base)
c0baea34 150 __THROW __nonnull ((1));
4708f2b1 151__END_NAMESPACE_STD
28f540f4 152
498afc54 153#ifdef __USE_MISC
28f540f4 154/* Convert a string to a quadword integer. */
7782d0bf 155__extension__
a784e502 156extern long long int strtoq (const char *__restrict __nptr,
be27d08c 157 char **__restrict __endptr, int __base)
c0baea34 158 __THROW __nonnull ((1));
28f540f4 159/* Convert a string to an unsigned quadword integer. */
7782d0bf 160__extension__
a784e502 161extern unsigned long long int strtouq (const char *__restrict __nptr,
c1422e5b 162 char **__restrict __endptr, int __base)
c0baea34 163 __THROW __nonnull ((1));
acd7f096 164#endif /* Use misc. */
28f540f4 165
acd7f096 166#ifdef __USE_ISOC99
7a5affeb 167__BEGIN_NAMESPACE_C99
76060ec0 168/* Convert a string to a quadword integer. */
7782d0bf 169__extension__
a784e502 170extern long long int strtoll (const char *__restrict __nptr,
be27d08c 171 char **__restrict __endptr, int __base)
c0baea34 172 __THROW __nonnull ((1));
76060ec0 173/* Convert a string to an unsigned quadword integer. */
7782d0bf 174__extension__
a784e502 175extern unsigned long long int strtoull (const char *__restrict __nptr,
c1422e5b 176 char **__restrict __endptr, int __base)
c0baea34 177 __THROW __nonnull ((1));
7a5affeb 178__END_NAMESPACE_C99
6a57d931 179#endif /* ISO C99 or use MISC. */
76060ec0
RM
180
181
0501d603
UD
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
8f0d3f49 185 information from several different locales. Another problem is
0501d603 186 the implementation of the internationalization handling in the
8f0d3f49
UD
187 ISO C++ standard library. To support this another set of
188 the functions using locale data exist which take an additional
0501d603
UD
189 argument.
190
8f0d3f49
UD
191 Attention: even though several *_l interfaces are part of POSIX:2008,
192 these are not. */
0501d603
UD
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. */
a784e502 200extern long int strtol_l (const char *__restrict __nptr,
1ab62b32 201 char **__restrict __endptr, int __base,
c0baea34 202 __locale_t __loc) __THROW __nonnull ((1, 4));
0501d603 203
a784e502 204extern unsigned long int strtoul_l (const char *__restrict __nptr,
1ab62b32 205 char **__restrict __endptr,
be27d08c 206 int __base, __locale_t __loc)
c0baea34 207 __THROW __nonnull ((1, 4));
0501d603 208
7782d0bf 209__extension__
a784e502 210extern long long int strtoll_l (const char *__restrict __nptr,
1ab62b32 211 char **__restrict __endptr, int __base,
be27d08c 212 __locale_t __loc)
c0baea34 213 __THROW __nonnull ((1, 4));
0501d603 214
7782d0bf 215__extension__
a784e502 216extern unsigned long long int strtoull_l (const char *__restrict __nptr,
1ab62b32
RM
217 char **__restrict __endptr,
218 int __base, __locale_t __loc)
c0baea34 219 __THROW __nonnull ((1, 4));
0501d603 220
a784e502 221extern double strtod_l (const char *__restrict __nptr,
1ab62b32 222 char **__restrict __endptr, __locale_t __loc)
c0baea34 223 __THROW __nonnull ((1, 3));
0501d603 224
a784e502 225extern float strtof_l (const char *__restrict __nptr,
be27d08c 226 char **__restrict __endptr, __locale_t __loc)
c0baea34 227 __THROW __nonnull ((1, 3));
0501d603 228
a784e502 229extern long double strtold_l (const char *__restrict __nptr,
1ab62b32 230 char **__restrict __endptr,
0476597b 231 __locale_t __loc)
c0baea34 232 __THROW __nonnull ((1, 3));
0501d603
UD
233#endif /* GNU */
234
f0bf9cb9 235
07c416ed 236#ifdef __USE_EXTERN_INLINES
7a5affeb 237__BEGIN_NAMESPACE_STD
b037a293 238__extern_inline int
a784e502 239__NTH (atoi (const char *__nptr))
2604afb1
UD
240{
241 return (int) strtol (__nptr, (char **) NULL, 10);
242}
b037a293 243__extern_inline long int
a784e502 244__NTH (atol (const char *__nptr))
2604afb1
UD
245{
246 return strtol (__nptr, (char **) NULL, 10);
247}
7a5affeb 248__END_NAMESPACE_STD
2604afb1 249
acd7f096 250# ifdef __USE_ISOC99
7a5affeb 251__BEGIN_NAMESPACE_C99
b037a293 252__extension__ __extern_inline long long int
a784e502 253__NTH (atoll (const char *__nptr))
2604afb1
UD
254{
255 return strtoll (__nptr, (char **) NULL, 10);
256}
7a5affeb 257__END_NAMESPACE_C99
2604afb1 258# endif
0c6cee5d 259#endif /* Optimizing and Inlining. */
28f540f4
RM
260
261
498afc54 262#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
bbed653c
RM
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. */
0476597b 266extern char *l64a (long int __n) __THROW __wur;
bbed653c 267
036cc82f 268/* Read a number from a string S in base 64 as above. */
a784e502 269extern long int a64l (const char *__s)
0476597b 270 __THROW __attribute_pure__ __nonnull ((1)) __wur;
28f540f4 271
acd7f096 272#endif /* Use misc || extended X/Open. */
b20e47cb 273
ed9a38e2 274#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
dfd2257a 275# include <sys/types.h> /* we need int32_t... */
b20e47cb 276
28f540f4
RM
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. */
61f9d0a3 282extern long int random (void) __THROW;
9ebb936d 283
28f540f4 284/* Seed the random number generator with the given number. */
c1422e5b 285extern void srandom (unsigned int __seed) __THROW;
28f540f4
RM
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. */
9323b58f 291extern char *initstate (unsigned int __seed, char *__statebuf,
be27d08c 292 size_t __statelen) __THROW __nonnull ((2));
9ebb936d 293
28f540f4
RM
294/* Switch the random number generator to state buffer STATEBUF,
295 which should have been previously initialized by `initstate'. */
be27d08c 296extern char *setstate (char *__statebuf) __THROW __nonnull ((1));
28f540f4 297
60478656 298
2604afb1 299# ifdef __USE_MISC
60478656
RM
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 {
b20e47cb
RM
306 int32_t *fptr; /* Front pointer. */
307 int32_t *rptr; /* Rear pointer. */
308 int32_t *state; /* Array of state values. */
60478656
RM
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. */
b20e47cb 312 int32_t *end_ptr; /* Pointer behind state table. */
60478656
RM
313 };
314
c1422e5b 315extern int random_r (struct random_data *__restrict __buf,
be27d08c 316 int32_t *__restrict __result) __THROW __nonnull ((1, 2));
8a523922 317
be27d08c
UD
318extern int srandom_r (unsigned int __seed, struct random_data *__buf)
319 __THROW __nonnull ((2));
8a523922 320
9323b58f 321extern int initstate_r (unsigned int __seed, char *__restrict __statebuf,
c1422e5b 322 size_t __statelen,
be27d08c
UD
323 struct random_data *__restrict __buf)
324 __THROW __nonnull ((2, 4));
8a523922 325
9323b58f 326extern int setstate_r (char *__restrict __statebuf,
be27d08c
UD
327 struct random_data *__restrict __buf)
328 __THROW __nonnull ((1, 2));
2604afb1 329# endif /* Use misc. */
acd7f096 330#endif /* Use extended X/Open || misc. */
60478656
RM
331
332
7a5affeb 333__BEGIN_NAMESPACE_STD
2c6fe0bd 334/* Return a random integer between 0 and RAND_MAX inclusive. */
c1422e5b 335extern int rand (void) __THROW;
2c6fe0bd 336/* Seed the random number generator with the given number. */
c1422e5b 337extern void srand (unsigned int __seed) __THROW;
7a5affeb 338__END_NAMESPACE_STD
2c6fe0bd 339
b098852a 340#ifdef __USE_POSIX199506
47707456 341/* Reentrant interface according to POSIX.1. */
c1422e5b 342extern int rand_r (unsigned int *__seed) __THROW;
47707456
UD
343#endif
344
2c6fe0bd 345
498afc54 346#if defined __USE_MISC || defined __USE_XOPEN
60478656
RM
347/* System V style 48-bit random number generator functions. */
348
2c6fe0bd 349/* Return non-negative, double-precision floating-point value in [0.0,1.0). */
c1422e5b 350extern double drand48 (void) __THROW;
be27d08c 351extern double erand48 (unsigned short int __xsubi[3]) __THROW __nonnull ((1));
2c6fe0bd
UD
352
353/* Return non-negative, long integer in [0,2^31). */
c1422e5b 354extern long int lrand48 (void) __THROW;
be27d08c
UD
355extern long int nrand48 (unsigned short int __xsubi[3])
356 __THROW __nonnull ((1));
2c6fe0bd
UD
357
358/* Return signed, long integers in [-2^31,2^31). */
c1422e5b 359extern long int mrand48 (void) __THROW;
be27d08c
UD
360extern long int jrand48 (unsigned short int __xsubi[3])
361 __THROW __nonnull ((1));
2c6fe0bd
UD
362
363/* Seed random number generator. */
c1422e5b 364extern void srand48 (long int __seedval) __THROW;
be27d08c
UD
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));
2c6fe0bd 368
d17c01f9
UD
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. */
60478656
RM
373struct drand48_data
374 {
d17c01f9
UD
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. */
828beb13
JM
379 __extension__ unsigned long long int __a; /* Factor in congruential
380 formula. */
60478656
RM
381 };
382
383/* Return non-negative, double-precision floating-point value in [0.0,1.0). */
c1422e5b 384extern int drand48_r (struct drand48_data *__restrict __buffer,
be27d08c 385 double *__restrict __result) __THROW __nonnull ((1, 2));
c1422e5b
UD
386extern int erand48_r (unsigned short int __xsubi[3],
387 struct drand48_data *__restrict __buffer,
be27d08c 388 double *__restrict __result) __THROW __nonnull ((1, 2));
2c6fe0bd 389
60478656 390/* Return non-negative, long integer in [0,2^31). */
c1422e5b 391extern int lrand48_r (struct drand48_data *__restrict __buffer,
be27d08c
UD
392 long int *__restrict __result)
393 __THROW __nonnull ((1, 2));
c1422e5b
UD
394extern int nrand48_r (unsigned short int __xsubi[3],
395 struct drand48_data *__restrict __buffer,
be27d08c
UD
396 long int *__restrict __result)
397 __THROW __nonnull ((1, 2));
2c6fe0bd 398
60478656 399/* Return signed, long integers in [-2^31,2^31). */
c1422e5b 400extern int mrand48_r (struct drand48_data *__restrict __buffer,
be27d08c
UD
401 long int *__restrict __result)
402 __THROW __nonnull ((1, 2));
c1422e5b
UD
403extern int jrand48_r (unsigned short int __xsubi[3],
404 struct drand48_data *__restrict __buffer,
be27d08c
UD
405 long int *__restrict __result)
406 __THROW __nonnull ((1, 2));
2c6fe0bd 407
60478656 408/* Seed random number generator. */
c1422e5b 409extern int srand48_r (long int __seedval, struct drand48_data *__buffer)
be27d08c 410 __THROW __nonnull ((2));
47f13fd4 411
c1422e5b 412extern int seed48_r (unsigned short int __seed16v[3],
be27d08c 413 struct drand48_data *__buffer) __THROW __nonnull ((1, 2));
47f13fd4 414
c1422e5b 415extern int lcong48_r (unsigned short int __param[7],
be27d08c
UD
416 struct drand48_data *__buffer)
417 __THROW __nonnull ((1, 2));
dfd2257a 418# endif /* Use misc. */
acd7f096 419#endif /* Use misc or X/Open. */
28f540f4 420
7ef90c15 421#endif /* don't just need malloc and calloc */
28f540f4 422
7ef90c15 423#ifndef __malloc_and_calloc_defined
7a5affeb
UD
424# define __malloc_and_calloc_defined
425__BEGIN_NAMESPACE_STD
28f540f4 426/* Allocate SIZE bytes of memory. */
0476597b 427extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
7ef90c15 428/* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
e9e9b245 429extern void *calloc (size_t __nmemb, size_t __size)
0476597b 430 __THROW __attribute_malloc__ __wur;
7a5affeb 431__END_NAMESPACE_STD
7ef90c15
UD
432#endif
433
434#ifndef __need_malloc_and_calloc
7a5affeb 435__BEGIN_NAMESPACE_STD
28f540f4 436/* Re-allocate the previously allocated block
c1422e5b 437 in PTR, making the new block SIZE bytes long. */
1c3e748e
UD
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. */
0476597b 441extern void *realloc (void *__ptr, size_t __size)
1c3e748e 442 __THROW __attribute_warn_unused_result__;
28f540f4 443/* Free a block allocated by `malloc', `realloc' or `calloc'. */
c1422e5b 444extern void free (void *__ptr) __THROW;
7a5affeb 445__END_NAMESPACE_STD
28f540f4
RM
446
447#ifdef __USE_MISC
448/* Free a block. An alias for `free'. (Sun Unices). */
c1422e5b 449extern void cfree (void *__ptr) __THROW;
28f540f4
RM
450#endif /* Use misc. */
451
acd7f096 452#ifdef __USE_MISC
2604afb1 453# include <alloca.h>
acd7f096 454#endif /* Use misc. */
28f540f4 455
c589e093 456#if (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K) \
498afc54 457 || defined __USE_MISC
28f540f4 458/* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */
0476597b 459extern void *valloc (size_t __size) __THROW __attribute_malloc__ __wur;
28f540f4
RM
460#endif
461
0758ea0c 462#ifdef __USE_XOPEN2K
c8c73ac3 463/* Allocate memory of SIZE bytes with an alignment of ALIGNMENT. */
61f9d0a3 464extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size)
5bcbe69f 465 __THROW __nonnull ((1)) __wur;
0758ea0c 466#endif
28f540f4 467
380d7e87
UD
468#ifdef __USE_ISOC11
469/* ISO C variant of aligned allocation. */
8b43a4cc 470extern void *aligned_alloc (size_t __alignment, size_t __size)
4be9b544 471 __THROW __attribute_malloc__ __attribute_alloc_size__ ((2)) __wur;
380d7e87
UD
472#endif
473
7a5affeb 474__BEGIN_NAMESPACE_STD
28f540f4 475/* Abort execution and generate a core-dump. */
c1422e5b 476extern void abort (void) __THROW __attribute__ ((__noreturn__));
28f540f4
RM
477
478
479/* Register a function to be called when `exit' is called. */
be27d08c 480extern int atexit (void (*__func) (void)) __THROW __nonnull ((1));
610e67ed 481
4e9e7a35 482#if defined __USE_ISOC11 || defined __USE_ISOCXX11
610e67ed
UD
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
7a5affeb 491__END_NAMESPACE_STD
28f540f4
RM
492
493#ifdef __USE_MISC
494/* Register a function to be called with the status
495 given to `exit' and the given argument. */
c1422e5b 496extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg)
be27d08c 497 __THROW __nonnull ((1));
28f540f4
RM
498#endif
499
7a5affeb 500__BEGIN_NAMESPACE_STD
28f540f4 501/* Call all functions registered with `atexit' and `on_exit',
610e67ed 502 in the reverse of the order in which they were registered,
28f540f4 503 perform stdio cleanup, and terminate program execution with STATUS. */
c1422e5b 504extern void exit (int __status) __THROW __attribute__ ((__noreturn__));
610e67ed 505
4e9e7a35 506#if defined __USE_ISOC11 || defined __USE_ISOCXX11
610e67ed
UD
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
7a5affeb 512__END_NAMESPACE_STD
28f540f4 513
ec751a23 514#ifdef __USE_ISOC99
7a5affeb 515__BEGIN_NAMESPACE_C99
e518937a
UD
516/* Terminate the program with STATUS without calling any of the
517 functions registered with `atexit' or `on_exit'. */
c1422e5b 518extern void _Exit (int __status) __THROW __attribute__ ((__noreturn__));
7a5affeb 519__END_NAMESPACE_C99
e518937a
UD
520#endif
521
28f540f4 522
7a5affeb 523__BEGIN_NAMESPACE_STD
28f540f4 524/* Return the value of envariable NAME, or NULL if it doesn't exist. */
a784e502 525extern char *getenv (const char *__name) __THROW __nonnull ((1)) __wur;
7a5affeb 526__END_NAMESPACE_STD
28f540f4 527
84b3fd84 528#ifdef __USE_GNU
d68171ed
UD
529/* This function is similar to the above but returns NULL if the
530 programs is running with SUID or SGID enabled. */
84b3fd84 531extern char *secure_getenv (const char *__name)
0476597b 532 __THROW __nonnull ((1)) __wur;
84b3fd84 533#endif
d68171ed 534
498afc54 535#if defined __USE_MISC || defined __USE_XOPEN
28f540f4
RM
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. */
be27d08c 539extern int putenv (char *__string) __THROW __nonnull ((1));
28f540f4
RM
540#endif
541
acd7f096 542#ifdef __USE_XOPEN2K
28f540f4
RM
543/* Set NAME to VALUE in the environment.
544 If REPLACE is nonzero, overwrite an existing value. */
a784e502 545extern int setenv (const char *__name, const char *__value, int __replace)
90692538 546 __THROW __nonnull ((2));
196980f5
RM
547
548/* Remove the variable NAME from the environment. */
a784e502 549extern int unsetenv (const char *__name) __THROW __nonnull ((1));
28f540f4
RM
550#endif
551
f0e44959
UD
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. */
c1422e5b 556extern int clearenv (void) __THROW;
f0e44959
UD
557#endif
558
2c6fe0bd 559
52e96a80 560#if defined __USE_MISC \
9bde902c 561 || (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8)
2c6fe0bd
UD
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.
349fa79f
AJ
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));
f095bb72 568#endif
2c6fe0bd 569
acd7f096 570#if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
2c6fe0bd
UD
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,
2c008571
UD
575 or -1 if it cannot create a uniquely-named file.
576
7f3146e7 577 This function is a possible cancellation point and therefore not
2c008571 578 marked with __THROW. */
85adf316 579# ifndef __USE_FILE_OFFSET64
0476597b 580extern int mkstemp (char *__template) __nonnull ((1)) __wur;
85adf316
UD
581# else
582# ifdef __REDIRECT
0476597b
UD
583extern int __REDIRECT (mkstemp, (char *__template), mkstemp64)
584 __nonnull ((1)) __wur;
85adf316
UD
585# else
586# define mkstemp mkstemp64
587# endif
588# endif
589# ifdef __USE_LARGEFILE64
0476597b 590extern int mkstemp64 (char *__template) __nonnull ((1)) __wur;
85adf316 591# endif
2c6fe0bd
UD
592#endif
593
7f3146e7
UD
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
acd7f096 617#ifdef __USE_XOPEN2K8
2e65ca2b
UD
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. */
0476597b 623extern char *mkdtemp (char *__template) __THROW __nonnull ((1)) __wur;
2e65ca2b
UD
624#endif
625
d7e23b02
UD
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
4c1423ed 631 This function is a possible cancellation point and therefore not
d7e23b02
UD
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
3a83202d
UD
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
d7e23b02
UD
669#endif
670
2c6fe0bd 671
7a5affeb 672__BEGIN_NAMESPACE_STD
2c008571
UD
673/* Execute the given line as a shell command.
674
675 This function is a cancellation point and therefore not marked with
676 __THROW. */
a784e502 677extern int system (const char *__command) __wur;
7a5affeb 678__END_NAMESPACE_STD
28f540f4
RM
679
680
fa0bc87c
RM
681#ifdef __USE_GNU
682/* Return a malloc'd string containing the canonical absolute name of the
11bf311e 683 existing named file. */
a784e502 684extern char *canonicalize_file_name (const char *__name)
0476597b 685 __THROW __nonnull ((1)) __wur;
fa0bc87c
RM
686#endif
687
498afc54 688#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
b7674b11
UD
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. */
a784e502 694extern char *realpath (const char *__restrict __name,
0476597b 695 char *__restrict __resolved) __THROW __wur;
fa0bc87c
RM
696#endif
697
698
28f540f4 699/* Shorthand for type of comparison functions. */
60478656 700#ifndef __COMPAR_FN_T
2604afb1 701# define __COMPAR_FN_T
a784e502 702typedef int (*__compar_fn_t) (const void *, const void *);
28f540f4 703
2604afb1 704# ifdef __USE_GNU
28f540f4 705typedef __compar_fn_t comparison_fn_t;
2604afb1 706# endif
28f540f4 707#endif
e458144c 708#ifdef __USE_GNU
a784e502 709typedef int (*__compar_d_fn_t) (const void *, const void *, void *);
e458144c 710#endif
28f540f4 711
7a5affeb 712__BEGIN_NAMESPACE_STD
28f540f4
RM
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. */
a784e502 715extern void *bsearch (const void *__key, const void *__base,
be27d08c 716 size_t __nmemb, size_t __size, __compar_fn_t __compar)
0476597b 717 __nonnull ((1, 2, 5)) __wur;
28f540f4 718
41eda41d
OB
719#ifdef __USE_EXTERN_INLINES
720# include <bits/stdlib-bsearch.h>
721#endif
722
28f540f4
RM
723/* Sort NMEMB elements of BASE, of SIZE bytes each,
724 using COMPAR to perform the comparisons. */
c1422e5b 725extern void qsort (void *__base, size_t __nmemb, size_t __size,
be27d08c 726 __compar_fn_t __compar) __nonnull ((1, 4));
e458144c
UD
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
28f540f4
RM
732
733
28f540f4 734/* Return the absolute value of X. */
0476597b
UD
735extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
736extern long int labs (long int __x) __THROW __attribute__ ((__const__)) __wur;
7a5affeb
UD
737__END_NAMESPACE_STD
738
ec751a23 739#ifdef __USE_ISOC99
c1422e5b 740__extension__ extern long long int llabs (long long int __x)
0476597b 741 __THROW __attribute__ ((__const__)) __wur;
59dd8641 742#endif
28f540f4
RM
743
744
7a5affeb 745__BEGIN_NAMESPACE_STD
59dd8641 746/* Return the `div_t', `ldiv_t' or `lldiv_t' representation
28f540f4
RM
747 of the value of NUMER over DENOM. */
748/* GCC may have built-ins for these someday. */
c1422e5b 749extern div_t div (int __numer, int __denom)
0476597b 750 __THROW __attribute__ ((__const__)) __wur;
c1422e5b 751extern ldiv_t ldiv (long int __numer, long int __denom)
0476597b 752 __THROW __attribute__ ((__const__)) __wur;
7a5affeb
UD
753__END_NAMESPACE_STD
754
ec751a23 755#ifdef __USE_ISOC99
7a5affeb 756__BEGIN_NAMESPACE_C99
c1422e5b
UD
757__extension__ extern lldiv_t lldiv (long long int __numer,
758 long long int __denom)
0476597b 759 __THROW __attribute__ ((__const__)) __wur;
7a5affeb 760__END_NAMESPACE_C99
59dd8641 761#endif
28f540f4
RM
762
763
9bde902c 764#if (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8) \
498afc54 765 || defined __USE_MISC
60478656
RM
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. */
c1422e5b 772extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt,
0476597b 773 int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur;
60478656
RM
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. */
c1422e5b 778extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt,
0476597b 779 int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur;
60478656
RM
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. */
be27d08c 784extern char *gcvt (double __value, int __ndigit, char *__buf)
0476597b 785 __THROW __nonnull ((3)) __wur;
4220c3ef 786#endif
60478656 787
4220c3ef 788#ifdef __USE_MISC
2064087b 789/* Long double versions of above functions. */
c1422e5b 790extern char *qecvt (long double __value, int __ndigit,
be27d08c 791 int *__restrict __decpt, int *__restrict __sign)
0476597b 792 __THROW __nonnull ((3, 4)) __wur;
c1422e5b 793extern char *qfcvt (long double __value, int __ndigit,
be27d08c 794 int *__restrict __decpt, int *__restrict __sign)
0476597b 795 __THROW __nonnull ((3, 4)) __wur;
be27d08c 796extern char *qgcvt (long double __value, int __ndigit, char *__buf)
0476597b 797 __THROW __nonnull ((3)) __wur;
2064087b
RM
798
799
60478656
RM
800/* Reentrant version of the functions above which provide their own
801 buffers. */
c1422e5b
UD
802extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt,
803 int *__restrict __sign, char *__restrict __buf,
be27d08c 804 size_t __len) __THROW __nonnull ((3, 4, 5));
c1422e5b
UD
805extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt,
806 int *__restrict __sign, char *__restrict __buf,
be27d08c 807 size_t __len) __THROW __nonnull ((3, 4, 5));
c1422e5b
UD
808
809extern int qecvt_r (long double __value, int __ndigit,
810 int *__restrict __decpt, int *__restrict __sign,
be27d08c
UD
811 char *__restrict __buf, size_t __len)
812 __THROW __nonnull ((3, 4, 5));
c1422e5b
UD
813extern int qfcvt_r (long double __value, int __ndigit,
814 int *__restrict __decpt, int *__restrict __sign,
be27d08c
UD
815 char *__restrict __buf, size_t __len)
816 __THROW __nonnull ((3, 4, 5));
4220c3ef 817#endif /* misc */
60478656
RM
818
819
7a5affeb 820__BEGIN_NAMESPACE_STD
28f540f4
RM
821/* Return the length of the multibyte character
822 in S, which is no longer than N. */
a065ceff 823extern int mblen (const char *__s, size_t __n) __THROW;
28f540f4
RM
824/* Return the length of the given multibyte character,
825 putting its `wchar_t' representation in *PWC. */
c1422e5b 826extern int mbtowc (wchar_t *__restrict __pwc,
a065ceff 827 const char *__restrict __s, size_t __n) __THROW;
28f540f4
RM
828/* Put the multibyte character represented
829 by WCHAR in S, returning its length. */
a065ceff 830extern int wctomb (char *__s, wchar_t __wchar) __THROW;
28f540f4 831
28f540f4
RM
832
833/* Convert a multibyte string to a wide char string. */
c1422e5b 834extern size_t mbstowcs (wchar_t *__restrict __pwcs,
a784e502 835 const char *__restrict __s, size_t __n) __THROW;
28f540f4 836/* Convert a wide char string to multibyte string. */
c1422e5b 837extern size_t wcstombs (char *__restrict __s,
a784e502 838 const wchar_t *__restrict __pwcs, size_t __n)
c1422e5b 839 __THROW;
7a5affeb 840__END_NAMESPACE_STD
28f540f4
RM
841
842
498afc54 843#ifdef __USE_MISC
857fa1b8
RM
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. */
a784e502 848extern int rpmatch (const char *__response) __THROW __nonnull ((1)) __wur;
857fa1b8
RM
849#endif
850
851
f095bb72 852#if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
2064087b
RM
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
2604afb1 858 token or at the terminating NUL character. */
c1422e5b 859extern int getsubopt (char **__restrict __optionp,
a784e502 860 char *const *__restrict __tokens,
be27d08c 861 char **__restrict __valuep)
0476597b 862 __THROW __nonnull ((1, 2, 3)) __wur;
2064087b
RM
863#endif
864
865
2c6fe0bd 866#ifdef __USE_XOPEN
2c6fe0bd 867/* Setup DES tables according KEY. */
a784e502 868extern void setkey (const char *__key) __THROW __nonnull ((1));
0101a56f
UD
869#endif
870
6591c335
UD
871
872/* X/Open pseudo terminal handling. */
873
f095bb72 874#ifdef __USE_XOPEN2KXSI
0101a56f 875/* Return a master pseudo-terminal handle. */
0476597b 876extern int posix_openpt (int __oflag) __wur;
0101a56f
UD
877#endif
878
0014680d 879#ifdef __USE_XOPEN_EXTENDED
6591c335
UD
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. */
c1422e5b 884extern int grantpt (int __fd) __THROW;
6591c335
UD
885
886/* Release an internal lock so the slave can be opened.
887 Call after grantpt(). */
c1422e5b 888extern int unlockpt (int __fd) __THROW;
6591c335 889
6f65e668 890/* Return the pathname of the pseudo terminal slave associated with
4bca4c17
UD
891 the master FD is open on, or NULL on errors.
892 The returned storage is good until the next call to this function. */
0476597b 893extern char *ptsname (int __fd) __THROW __wur;
2c6fe0bd
UD
894#endif
895
6591c335 896#ifdef __USE_GNU
4bca4c17
UD
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. */
be27d08c
UD
900extern int ptsname_r (int __fd, char *__buf, size_t __buflen)
901 __THROW __nonnull ((2));
6591c335 902
4bca4c17 903/* Open a master pseudo terminal and return its file descriptor. */
f1c30c98 904extern int getpt (void);
6591c335 905#endif
2c6fe0bd 906
498afc54 907#ifdef __USE_MISC
b2277c15
RM
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. */
be27d08c
UD
911extern int getloadavg (double __loadavg[], int __nelem)
912 __THROW __nonnull ((1));
b2277c15
RM
913#endif
914
4242d968
JM
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
f62c8abc 921#include <bits/stdlib-float.h>
b799f91d
UD
922
923/* Define some macros helping to catch buffer overflows. */
5ac3ea17 924#if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
b799f91d
UD
925# include <bits/stdlib.h>
926#endif
c6251f03
RM
927#ifdef __LDBL_COMPAT
928# include <bits/stdlib-ldbl.h>
929#endif
b799f91d 930
7ef90c15
UD
931#endif /* don't just need malloc and calloc */
932#undef __need_malloc_and_calloc
933
28f540f4
RM
934__END_DECLS
935
936#endif /* stdlib.h */