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