OSDN Git Service

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