OSDN Git Service

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