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