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