OSDN Git Service

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