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