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