1 /* Copyright (C) 1991-2002, 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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
20 * ISO C99 Standard: 7.20 General utilities <stdlib.h>
27 /* Get size_t, wchar_t and NULL from <stddef.h>. */
29 #ifndef __need_malloc_and_calloc
30 #ifdef __UCLIBC_HAS_WCHAR__
31 # define __need_wchar_t
39 #ifndef __need_malloc_and_calloc
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>
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. */
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; }))
57 # define __WAIT_INT(status) (*(int *) &(status))
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. */
65 # if !defined __GNUC__ || __GNUC__ < 2 || defined __cplusplus
66 # define __WAIT_STATUS void *
67 # define __WAIT_STATUS_DEFN void *
69 /* This works in GCC 2.6.1 and later. */
74 } __WAIT_STATUS __attribute__ ((__transparent_union__));
75 # define __WAIT_STATUS_DEFN int *
78 # else /* Don't use BSD. */
80 # define __WAIT_INT(status) (status)
81 # define __WAIT_STATUS int *
82 # define __WAIT_STATUS_DEFN int *
84 # endif /* Use BSD. */
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. */
96 /* Returned by `div'. */
99 int quot; /* Quotient. */
100 int rem; /* Remainder. */
103 /* Returned by `ldiv'. */
104 #ifndef __ldiv_t_defined
107 long int quot; /* Quotient. */
108 long int rem; /* Remainder. */
110 # define __ldiv_t_defined 1
114 #if defined __USE_ISOC99 && !defined __lldiv_t_defined
115 __BEGIN_NAMESPACE_C99
116 /* Returned by `lldiv'. */
117 __extension__ typedef struct
119 long long int quot; /* Quotient. */
120 long long int rem; /* Remainder. */
122 # define __lldiv_t_defined 1
127 /* The largest number rand will return (same as INT_MAX). */
128 #define RAND_MAX 2147483647
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. */
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;
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__;
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__;
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;
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;
179 extern long double strtold (__const char *__restrict __nptr,
180 char **__restrict __endptr) __THROW;
183 #endif /* __UCLIBC_HAS_FLOATS__ */
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)
195 #if defined __USE_BSD
196 /* Convert a string to a quadword integer. */
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. */
202 extern unsigned long long int strtouq (__const char *__restrict __nptr,
203 char **__restrict __endptr, int __base)
205 #endif /* GCC and use BSD. */
207 #if defined __USE_ISOC99 || defined __USE_MISC
208 __BEGIN_NAMESPACE_C99
209 /* Convert a string to a quadword integer. */
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. */
215 extern unsigned long long int strtoull (__const char *__restrict __nptr,
216 char **__restrict __endptr, int __base)
219 #endif /* ISO C99 or GCC and use MISC. */
222 #ifdef __UCLIBC_HAS_XLOCALE__
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
232 Attention: all these functions are *not* standardized in any form.
233 This is a proof-of-concept implementation. */
235 /* Structure for reentrant locale using functions. This is an
236 (almost) opaque type for the user level programs. */
237 # include <xlocale.h>
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;
245 extern unsigned long int strtoul_l (__const char *__restrict __nptr,
246 char **__restrict __endptr,
247 int __base, __locale_t __loc) __THROW;
250 extern long long int strtoll_l (__const char *__restrict __nptr,
251 char **__restrict __endptr, int __base,
252 __locale_t __loc) __THROW;
255 extern unsigned long long int strtoull_l (__const char *__restrict __nptr,
256 char **__restrict __endptr,
257 int __base, __locale_t __loc)
260 extern double strtod_l (__const char *__restrict __nptr,
261 char **__restrict __endptr, __locale_t __loc)
264 extern float strtof_l (__const char *__restrict __nptr,
265 char **__restrict __endptr, __locale_t __loc) __THROW;
267 extern long double strtold_l (__const char *__restrict __nptr,
268 char **__restrict __endptr,
269 __locale_t __loc) __THROW;
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;
276 extern unsigned long int __strtoul_l (__const char *__restrict __nptr,
277 char **__restrict __endptr,
278 int __base, __locale_t __loc) __THROW;
281 extern long long int __strtoll_l (__const char *__restrict __nptr,
282 char **__restrict __endptr, int __base,
283 __locale_t __loc) __THROW;
286 extern unsigned long long int __strtoull_l (__const char *__restrict __nptr,
287 char **__restrict __endptr,
288 int __base, __locale_t __loc)
291 extern double __strtod_l (__const char *__restrict __nptr,
292 char **__restrict __endptr, __locale_t __loc)
295 extern float __strtof_l (__const char *__restrict __nptr,
296 char **__restrict __endptr, __locale_t __loc) __THROW;
298 extern long double __strtold_l (__const char *__restrict __nptr,
299 char **__restrict __endptr,
300 __locale_t __loc) __THROW;
302 #endif /* __UCLIBC_HAS_XLOCALE__ */
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
309 extern char *l64a (long int __n) __THROW;
311 /* Read a number from a string S in base 64 as above. */
312 extern long int a64l (__const char *__s) __THROW __attribute_pure__;
314 #endif /* Use SVID || extended X/Open. */
316 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED || defined __USE_BSD
317 # include <sys/types.h> /* we need int32_t... */
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;
326 /* Seed the random number generator with the given number. */
327 extern void srandom (unsigned int __seed) __THROW;
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;
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;
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. */
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. */
357 extern int random_r (struct random_data *__restrict __buf,
358 int32_t *__restrict __result) __THROW;
360 extern int srandom_r (unsigned int __seed, struct random_data *__buf) __THROW;
362 extern int initstate_r (unsigned int __seed, char *__restrict __statebuf,
364 struct random_data *__restrict __buf) __THROW;
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. */
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;
380 /* Reentrant interface according to POSIX.1. */
381 extern int rand_r (unsigned int *__seed) __THROW;
385 #if defined __USE_SVID || defined __USE_XOPEN
386 /* System V style 48-bit random number generator functions. */
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__ */
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;
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;
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;
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. */
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. */
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__ */
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;
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;
443 /* Seed random number generator. */
444 extern int srand48_r (long int __seedval, struct drand48_data *__buffer)
447 extern int seed48_r (unsigned short int __seed16v[3],
448 struct drand48_data *__buffer) __THROW;
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. */
455 #endif /* don't just need malloc and calloc */
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__;
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;
478 /* Free a block. An alias for `free'. (Sun Unices). */
479 extern void cfree (void *__ptr) __THROW;
480 #endif /* Use misc. */
482 #if defined __USE_GNU || defined __USE_BSD || defined __USE_MISC
484 #endif /* Use GNU, BSD, or misc. */
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__;
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__;
497 __BEGIN_NAMESPACE_STD
498 /* Abort execution and generate a core-dump. */
499 extern void abort (void) __THROW __attribute__ ((__noreturn__));
502 /* Register a function to be called when `exit' is called. */
503 extern int atexit (void (*__func) (void)) __THROW;
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)
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__));
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__));
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;
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;
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;
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)
551 /* Remove the variable NAME from the environment. */
552 extern int unsetenv (__const char *__name) __THROW;
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
560 # define __UCLIBC_MAX_ATEXIT 20
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;
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;
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.
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);
591 extern int __REDIRECT (mkstemp, (char *__template), mkstemp64);
593 # define mkstemp mkstemp64
596 # ifdef __USE_LARGEFILE64
597 extern int mkstemp64 (char *__template);
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;
611 __BEGIN_NAMESPACE_STD
612 /* Execute the given line as a shell command.
614 This function is a cancellation point and therefore not marked with
616 extern int system (__const char *__command);
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
627 extern char *realpath (__const char *__restrict __name,
628 char *__restrict __resolved) __THROW;
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 *);
638 typedef __compar_fn_t comparison_fn_t;
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);
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);
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__));
660 __extension__ extern long long int llabs (long long int __x)
661 __THROW __attribute__ ((__const__));
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__));
676 __BEGIN_NAMESPACE_C99
677 __extension__ extern lldiv_t lldiv (long long int __numer,
678 long long int __denom)
679 __THROW __attribute__ ((__const__));
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;
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)
706 #endif /* __UCLIBC_HAS_WCHAR__ */
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;
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;
732 /* Setup DES tables according KEY. */
733 extern void setkey (__const char *__key) __THROW;
737 /* X/Open pseudo terminal handling. */
740 /* Return a master pseudo-terminal handle. */
741 extern int posix_openpt (int __oflag) __THROW;
745 /* The next four functions all take a master pseudo-tty fd and
746 perform an operation on the associated slave: */
748 /* Chown the slave to the calling user. */
749 extern int grantpt (int __fd) __THROW;
751 /* Release an internal lock so the slave can be opened.
752 Call after grantpt(). */
753 extern int unlockpt (int __fd) __THROW;
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;
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;
767 /* Open a master pseudo terminal and return its file descriptor. */
768 extern int getpt (void) __THROW;
771 #endif /* don't just need malloc and calloc */
772 #undef __need_malloc_and_calloc
776 #endif /* stdlib.h */