OSDN Git Service

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