OSDN Git Service

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