OSDN Git Service

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