Back to index

glibc  2.9
stdlib.h
Go to the documentation of this file.
00001 /* Copyright (C) 1991-2003,2004,2005,2006,2007 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 /*
00020  *     ISO C99 Standard: 7.20 General utilities  <stdlib.h>
00021  */
00022 
00023 #ifndef       _STDLIB_H
00024 
00025 #include <features.h>
00026 
00027 /* Get size_t, wchar_t and NULL from <stddef.h>.  */
00028 #define              __need_size_t
00029 #ifndef __need_malloc_and_calloc
00030 # define      __need_wchar_t
00031 # define      __need_NULL
00032 #endif
00033 #include <stddef.h>
00034 
00035 __BEGIN_DECLS
00036 
00037 #ifndef __need_malloc_and_calloc
00038 #define       _STDLIB_H     1
00039 
00040 #if defined __USE_XOPEN && !defined _SYS_WAIT_H
00041 /* XPG requires a few symbols from <sys/wait.h> being defined.  */
00042 # include <bits/waitflags.h>
00043 # include <bits/waitstatus.h>
00044 
00045 # ifdef __USE_BSD
00046 
00047 /* Lots of hair to allow traditional BSD use of `union wait'
00048    as well as POSIX.1 use of `int' for the status word.  */
00049 
00050 #  if defined __GNUC__ && !defined __cplusplus
00051 #   define __WAIT_INT(status)                                               \
00052   (__extension__ ({ union { __typeof(status) __in; int __i; } __u;          \
00053                   __u.__in = (status); __u.__i; }))
00054 #  else
00055 #   define __WAIT_INT(status)      (*(int *) &(status))
00056 #  endif
00057 
00058 /* This is the type of the argument to `wait'.  The funky union
00059    causes redeclarations with ether `int *' or `union wait *' to be
00060    allowed without complaint.  __WAIT_STATUS_DEFN is the type used in
00061    the actual function definitions.  */
00062 
00063 #  if !defined __GNUC__ || __GNUC__ < 2 || defined __cplusplus
00064 #   define __WAIT_STATUS    void *
00065 #   define __WAIT_STATUS_DEFN      void *
00066 #  else
00067 /* This works in GCC 2.6.1 and later.  */
00068 typedef union
00069   {
00070     union wait *__uptr;
00071     int *__iptr;
00072   } __WAIT_STATUS __attribute__ ((__transparent_union__));
00073 #   define __WAIT_STATUS_DEFN      int *
00074 #  endif
00075 
00076 # else /* Don't use BSD.  */
00077 
00078 #  define __WAIT_INT(status)       (status)
00079 #  define __WAIT_STATUS            int *
00080 #  define __WAIT_STATUS_DEFN       int *
00081 
00082 # endif /* Use BSD.  */
00083 
00084 /* Define the macros <sys/wait.h> also would define this way.  */
00085 # define WEXITSTATUS(status)       __WEXITSTATUS(__WAIT_INT(status))
00086 # define WTERMSIG(status)   __WTERMSIG(__WAIT_INT(status))
00087 # define WSTOPSIG(status)   __WSTOPSIG(__WAIT_INT(status))
00088 # define WIFEXITED(status)  __WIFEXITED(__WAIT_INT(status))
00089 # define WIFSIGNALED(status)       __WIFSIGNALED(__WAIT_INT(status))
00090 # define WIFSTOPPED(status) __WIFSTOPPED(__WAIT_INT(status))
00091 # ifdef __WIFCONTINUED
00092 #  define WIFCONTINUED(status)     __WIFCONTINUED(__WAIT_INT(status))
00093 # endif
00094 #endif /* X/Open and <sys/wait.h> not included.  */
00095 
00096 __BEGIN_NAMESPACE_STD
00097 /* Returned by `div'.  */
00098 typedef struct
00099   {
00100     int quot;               /* Quotient.  */
00101     int rem;                /* Remainder.  */
00102   } div_t;
00103 
00104 /* Returned by `ldiv'.  */
00105 #ifndef __ldiv_t_defined
00106 typedef struct
00107   {
00108     long int quot;          /* Quotient.  */
00109     long int rem;           /* Remainder.  */
00110   } ldiv_t;
00111 # define __ldiv_t_defined   1
00112 #endif
00113 __END_NAMESPACE_STD
00114 
00115 #if defined __USE_ISOC99 && !defined __lldiv_t_defined
00116 __BEGIN_NAMESPACE_C99
00117 /* Returned by `lldiv'.  */
00118 __extension__ typedef struct
00119   {
00120     long long int quot;            /* Quotient.  */
00121     long long int rem;             /* Remainder.  */
00122   } lldiv_t;
00123 # define __lldiv_t_defined  1
00124 __END_NAMESPACE_C99
00125 #endif
00126 
00127 
00128 /* The largest number rand will return (same as INT_MAX).  */
00129 #define       RAND_MAX      2147483647
00130 
00131 
00132 /* We define these the same for all machines.
00133    Changes from this to the outside world should be done in `_exit'.  */
00134 #define       EXIT_FAILURE  1      /* Failing exit status.  */
00135 #define       EXIT_SUCCESS  0      /* Successful exit status.  */
00136 
00137 
00138 /* Maximum length of a multibyte character in the current locale.  */
00139 #define       MB_CUR_MAX    (__ctype_get_mb_cur_max ())
00140 extern size_t __ctype_get_mb_cur_max (void) __THROW __wur;
00141 
00142 
00143 __BEGIN_NAMESPACE_STD
00144 /* Convert a string to a floating-point number.  */
00145 extern double atof (__const char *__nptr)
00146      __THROW __attribute_pure__ __nonnull ((1)) __wur;
00147 /* Convert a string to an integer.  */
00148 extern int atoi (__const char *__nptr)
00149      __THROW __attribute_pure__ __nonnull ((1)) __wur;
00150 /* Convert a string to a long integer.  */
00151 extern long int atol (__const char *__nptr)
00152      __THROW __attribute_pure__ __nonnull ((1)) __wur;
00153 __END_NAMESPACE_STD
00154 
00155 #if defined __USE_ISOC99 || (defined __GLIBC_HAVE_LONG_LONG && defined __USE_MISC)
00156 __BEGIN_NAMESPACE_C99
00157 /* Convert a string to a long long integer.  */
00158 __extension__ extern long long int atoll (__const char *__nptr)
00159      __THROW __attribute_pure__ __nonnull ((1)) __wur;
00160 __END_NAMESPACE_C99
00161 #endif
00162 
00163 __BEGIN_NAMESPACE_STD
00164 /* Convert a string to a floating-point number.  */
00165 extern double strtod (__const char *__restrict __nptr,
00166                     char **__restrict __endptr)
00167      __THROW __nonnull ((1)) __wur;
00168 __END_NAMESPACE_STD
00169 
00170 #ifdef __USE_ISOC99
00171 __BEGIN_NAMESPACE_C99
00172 /* Likewise for `float' and `long double' sizes of floating-point numbers.  */
00173 extern float strtof (__const char *__restrict __nptr,
00174                    char **__restrict __endptr) __THROW __nonnull ((1)) __wur;
00175 
00176 extern long double strtold (__const char *__restrict __nptr,
00177                          char **__restrict __endptr)
00178      __THROW __nonnull ((1)) __wur;
00179 __END_NAMESPACE_C99
00180 #endif
00181 
00182 __BEGIN_NAMESPACE_STD
00183 /* Convert a string to a long integer.  */
00184 extern long int strtol (__const char *__restrict __nptr,
00185                      char **__restrict __endptr, int __base)
00186      __THROW __nonnull ((1)) __wur;
00187 /* Convert a string to an unsigned long integer.  */
00188 extern unsigned long int strtoul (__const char *__restrict __nptr,
00189                               char **__restrict __endptr, int __base)
00190      __THROW __nonnull ((1)) __wur;
00191 __END_NAMESPACE_STD
00192 
00193 #if defined __GLIBC_HAVE_LONG_LONG && defined __USE_BSD
00194 /* Convert a string to a quadword integer.  */
00195 __extension__
00196 extern long long int strtoq (__const char *__restrict __nptr,
00197                           char **__restrict __endptr, int __base)
00198      __THROW __nonnull ((1)) __wur;
00199 /* Convert a string to an unsigned quadword integer.  */
00200 __extension__
00201 extern unsigned long long int strtouq (__const char *__restrict __nptr,
00202                                    char **__restrict __endptr, int __base)
00203      __THROW __nonnull ((1)) __wur;
00204 #endif /* GCC and use BSD.  */
00205 
00206 #if defined __USE_ISOC99 || (defined __GLIBC_HAVE_LONG_LONG && defined __USE_MISC)
00207 __BEGIN_NAMESPACE_C99
00208 /* Convert a string to a quadword integer.  */
00209 __extension__
00210 extern long long int strtoll (__const char *__restrict __nptr,
00211                            char **__restrict __endptr, int __base)
00212      __THROW __nonnull ((1)) __wur;
00213 /* Convert a string to an unsigned quadword integer.  */
00214 __extension__
00215 extern unsigned long long int strtoull (__const char *__restrict __nptr,
00216                                    char **__restrict __endptr, int __base)
00217      __THROW __nonnull ((1)) __wur;
00218 __END_NAMESPACE_C99
00219 #endif /* ISO C99 or GCC and use MISC.  */
00220 
00221 
00222 #ifdef __USE_GNU
00223 /* The concept of one static locale per category is not very well
00224    thought out.  Many applications will need to process its data using
00225    information from several different locales.  Another application is
00226    the implementation of the internationalization handling in the
00227    upcoming ISO C++ standard library.  To support this another set of
00228    the functions using locale data exist which have an additional
00229    argument.
00230 
00231    Attention: all these functions are *not* standardized in any form.
00232    This is a proof-of-concept implementation.  */
00233 
00234 /* Structure for reentrant locale using functions.  This is an
00235    (almost) opaque type for the user level programs.  */
00236 # include <xlocale.h>
00237 
00238 /* Special versions of the functions above which take the locale to
00239    use as an additional parameter.  */
00240 extern long int strtol_l (__const char *__restrict __nptr,
00241                        char **__restrict __endptr, int __base,
00242                        __locale_t __loc) __THROW __nonnull ((1, 4)) __wur;
00243 
00244 extern unsigned long int strtoul_l (__const char *__restrict __nptr,
00245                                 char **__restrict __endptr,
00246                                 int __base, __locale_t __loc)
00247      __THROW __nonnull ((1, 4)) __wur;
00248 
00249 __extension__
00250 extern long long int strtoll_l (__const char *__restrict __nptr,
00251                             char **__restrict __endptr, int __base,
00252                             __locale_t __loc)
00253      __THROW __nonnull ((1, 4)) __wur;
00254 
00255 __extension__
00256 extern unsigned long long int strtoull_l (__const char *__restrict __nptr,
00257                                      char **__restrict __endptr,
00258                                      int __base, __locale_t __loc)
00259      __THROW __nonnull ((1, 4)) __wur;
00260 
00261 extern double strtod_l (__const char *__restrict __nptr,
00262                      char **__restrict __endptr, __locale_t __loc)
00263      __THROW __nonnull ((1, 3)) __wur;
00264 
00265 extern float strtof_l (__const char *__restrict __nptr,
00266                      char **__restrict __endptr, __locale_t __loc)
00267      __THROW __nonnull ((1, 3)) __wur;
00268 
00269 extern long double strtold_l (__const char *__restrict __nptr,
00270                            char **__restrict __endptr,
00271                            __locale_t __loc)
00272      __THROW __nonnull ((1, 3)) __wur;
00273 #endif /* GNU */
00274 
00275 
00276 #ifdef __USE_EXTERN_INLINES
00277 __BEGIN_NAMESPACE_STD
00278 __extern_inline double
00279 __NTH (atof (__const char *__nptr))
00280 {
00281   return strtod (__nptr, (char **) NULL);
00282 }
00283 __extern_inline int
00284 __NTH (atoi (__const char *__nptr))
00285 {
00286   return (int) strtol (__nptr, (char **) NULL, 10);
00287 }
00288 __extern_inline long int
00289 __NTH (atol (__const char *__nptr))
00290 {
00291   return strtol (__nptr, (char **) NULL, 10);
00292 }
00293 __END_NAMESPACE_STD
00294 
00295 # if defined __USE_MISC || defined __USE_ISOC99
00296 __BEGIN_NAMESPACE_C99
00297 __extension__ __extern_inline long long int
00298 __NTH (atoll (__const char *__nptr))
00299 {
00300   return strtoll (__nptr, (char **) NULL, 10);
00301 }
00302 __END_NAMESPACE_C99
00303 # endif
00304 #endif /* Optimizing and Inlining.  */
00305 
00306 
00307 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED
00308 /* Convert N to base 64 using the digits "./0-9A-Za-z", least-significant
00309    digit first.  Returns a pointer to static storage overwritten by the
00310    next call.  */
00311 extern char *l64a (long int __n) __THROW __wur;
00312 
00313 /* Read a number from a string S in base 64 as above.  */
00314 extern long int a64l (__const char *__s)
00315      __THROW __attribute_pure__ __nonnull ((1)) __wur;
00316 
00317 #endif /* Use SVID || extended X/Open.  */
00318 
00319 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED || defined __USE_BSD
00320 # include <sys/types.h>     /* we need int32_t... */
00321 
00322 /* These are the functions that actually do things.  The `random', `srandom',
00323    `initstate' and `setstate' functions are those from BSD Unices.
00324    The `rand' and `srand' functions are required by the ANSI standard.
00325    We provide both interfaces to the same random number generator.  */
00326 /* Return a random long integer between 0 and RAND_MAX inclusive.  */
00327 extern long int random (void) __THROW;
00328 
00329 /* Seed the random number generator with the given number.  */
00330 extern void srandom (unsigned int __seed) __THROW;
00331 
00332 /* Initialize the random number generator to use state buffer STATEBUF,
00333    of length STATELEN, and seed it with SEED.  Optimal lengths are 8, 16,
00334    32, 64, 128 and 256, the bigger the better; values less than 8 will
00335    cause an error and values greater than 256 will be rounded down.  */
00336 extern char *initstate (unsigned int __seed, char *__statebuf,
00337                      size_t __statelen) __THROW __nonnull ((2));
00338 
00339 /* Switch the random number generator to state buffer STATEBUF,
00340    which should have been previously initialized by `initstate'.  */
00341 extern char *setstate (char *__statebuf) __THROW __nonnull ((1));
00342 
00343 
00344 # ifdef __USE_MISC
00345 /* Reentrant versions of the `random' family of functions.
00346    These functions all use the following data structure to contain
00347    state, rather than global state variables.  */
00348 
00349 struct random_data
00350   {
00351     int32_t *fptr;          /* Front pointer.  */
00352     int32_t *rptr;          /* Rear pointer.  */
00353     int32_t *state;         /* Array of state values.  */
00354     int rand_type;          /* Type of random number generator.  */
00355     int rand_deg;           /* Degree of random number generator.  */
00356     int rand_sep;           /* Distance between front and rear.  */
00357     int32_t *end_ptr;              /* Pointer behind state table.  */
00358   };
00359 
00360 extern int random_r (struct random_data *__restrict __buf,
00361                    int32_t *__restrict __result) __THROW __nonnull ((1, 2));
00362 
00363 extern int srandom_r (unsigned int __seed, struct random_data *__buf)
00364      __THROW __nonnull ((2));
00365 
00366 extern int initstate_r (unsigned int __seed, char *__restrict __statebuf,
00367                      size_t __statelen,
00368                      struct random_data *__restrict __buf)
00369      __THROW __nonnull ((2, 4));
00370 
00371 extern int setstate_r (char *__restrict __statebuf,
00372                      struct random_data *__restrict __buf)
00373      __THROW __nonnull ((1, 2));
00374 # endif       /* Use misc.  */
00375 #endif /* Use SVID || extended X/Open || BSD. */
00376 
00377 
00378 __BEGIN_NAMESPACE_STD
00379 /* Return a random integer between 0 and RAND_MAX inclusive.  */
00380 extern int rand (void) __THROW;
00381 /* Seed the random number generator with the given number.  */
00382 extern void srand (unsigned int __seed) __THROW;
00383 __END_NAMESPACE_STD
00384 
00385 #ifdef __USE_POSIX
00386 /* Reentrant interface according to POSIX.1.  */
00387 extern int rand_r (unsigned int *__seed) __THROW;
00388 #endif
00389 
00390 
00391 #if defined __USE_SVID || defined __USE_XOPEN
00392 /* System V style 48-bit random number generator functions.  */
00393 
00394 /* Return non-negative, double-precision floating-point value in [0.0,1.0).  */
00395 extern double drand48 (void) __THROW;
00396 extern double erand48 (unsigned short int __xsubi[3]) __THROW __nonnull ((1));
00397 
00398 /* Return non-negative, long integer in [0,2^31).  */
00399 extern long int lrand48 (void) __THROW;
00400 extern long int nrand48 (unsigned short int __xsubi[3])
00401      __THROW __nonnull ((1));
00402 
00403 /* Return signed, long integers in [-2^31,2^31).  */
00404 extern long int mrand48 (void) __THROW;
00405 extern long int jrand48 (unsigned short int __xsubi[3])
00406      __THROW __nonnull ((1));
00407 
00408 /* Seed random number generator.  */
00409 extern void srand48 (long int __seedval) __THROW;
00410 extern unsigned short int *seed48 (unsigned short int __seed16v[3])
00411      __THROW __nonnull ((1));
00412 extern void lcong48 (unsigned short int __param[7]) __THROW __nonnull ((1));
00413 
00414 # ifdef __USE_MISC
00415 /* Data structure for communication with thread safe versions.  This
00416    type is to be regarded as opaque.  It's only exported because users
00417    have to allocate objects of this type.  */
00418 struct drand48_data
00419   {
00420     unsigned short int __x[3];     /* Current state.  */
00421     unsigned short int __old_x[3]; /* Old state.  */
00422     unsigned short int __c; /* Additive const. in congruential formula.  */
00423     unsigned short int __init;     /* Flag for initializing.  */
00424     unsigned long long int __a;    /* Factor in congruential formula.  */
00425   };
00426 
00427 /* Return non-negative, double-precision floating-point value in [0.0,1.0).  */
00428 extern int drand48_r (struct drand48_data *__restrict __buffer,
00429                     double *__restrict __result) __THROW __nonnull ((1, 2));
00430 extern int erand48_r (unsigned short int __xsubi[3],
00431                     struct drand48_data *__restrict __buffer,
00432                     double *__restrict __result) __THROW __nonnull ((1, 2));
00433 
00434 /* Return non-negative, long integer in [0,2^31).  */
00435 extern int lrand48_r (struct drand48_data *__restrict __buffer,
00436                     long int *__restrict __result)
00437      __THROW __nonnull ((1, 2));
00438 extern int nrand48_r (unsigned short int __xsubi[3],
00439                     struct drand48_data *__restrict __buffer,
00440                     long int *__restrict __result)
00441      __THROW __nonnull ((1, 2));
00442 
00443 /* Return signed, long integers in [-2^31,2^31).  */
00444 extern int mrand48_r (struct drand48_data *__restrict __buffer,
00445                     long int *__restrict __result)
00446      __THROW __nonnull ((1, 2));
00447 extern int jrand48_r (unsigned short int __xsubi[3],
00448                     struct drand48_data *__restrict __buffer,
00449                     long int *__restrict __result)
00450      __THROW __nonnull ((1, 2));
00451 
00452 /* Seed random number generator.  */
00453 extern int srand48_r (long int __seedval, struct drand48_data *__buffer)
00454      __THROW __nonnull ((2));
00455 
00456 extern int seed48_r (unsigned short int __seed16v[3],
00457                    struct drand48_data *__buffer) __THROW __nonnull ((1, 2));
00458 
00459 extern int lcong48_r (unsigned short int __param[7],
00460                     struct drand48_data *__buffer)
00461      __THROW __nonnull ((1, 2));
00462 # endif       /* Use misc.  */
00463 #endif /* Use SVID or X/Open.  */
00464 
00465 #endif /* don't just need malloc and calloc */
00466 
00467 #ifndef __malloc_and_calloc_defined
00468 # define __malloc_and_calloc_defined
00469 __BEGIN_NAMESPACE_STD
00470 /* Allocate SIZE bytes of memory.  */
00471 extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
00472 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0.  */
00473 extern void *calloc (size_t __nmemb, size_t __size)
00474      __THROW __attribute_malloc__ __wur;
00475 __END_NAMESPACE_STD
00476 #endif
00477 
00478 #ifndef __need_malloc_and_calloc
00479 __BEGIN_NAMESPACE_STD
00480 /* Re-allocate the previously allocated block
00481    in PTR, making the new block SIZE bytes long.  */
00482 /* __attribute_malloc__ is not used, because if realloc returns
00483    the same pointer that was passed to it, aliasing needs to be allowed
00484    between objects pointed by the old and new pointers.  */
00485 extern void *realloc (void *__ptr, size_t __size)
00486      __THROW __attribute_warn_unused_result__;
00487 /* Free a block allocated by `malloc', `realloc' or `calloc'.  */
00488 extern void free (void *__ptr) __THROW;
00489 __END_NAMESPACE_STD
00490 
00491 #ifdef __USE_MISC
00492 /* Free a block.  An alias for `free'.    (Sun Unices).  */
00493 extern void cfree (void *__ptr) __THROW;
00494 #endif /* Use misc.  */
00495 
00496 #if defined __USE_GNU || defined __USE_BSD || defined __USE_MISC
00497 # include <alloca.h>
00498 #endif /* Use GNU, BSD, or misc.  */
00499 
00500 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
00501 /* Allocate SIZE bytes on a page boundary.  The storage cannot be freed.  */
00502 extern void *valloc (size_t __size) __THROW __attribute_malloc__ __wur;
00503 #endif
00504 
00505 #ifdef __USE_XOPEN2K
00506 /* Allocate memory of SIZE bytes with an alignment of ALIGNMENT.  */
00507 extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size)
00508      __THROW __nonnull ((1)) __wur;
00509 #endif
00510 
00511 __BEGIN_NAMESPACE_STD
00512 /* Abort execution and generate a core-dump.  */
00513 extern void abort (void) __THROW __attribute__ ((__noreturn__));
00514 
00515 
00516 /* Register a function to be called when `exit' is called.  */
00517 extern int atexit (void (*__func) (void)) __THROW __nonnull ((1));
00518 __END_NAMESPACE_STD
00519 
00520 #ifdef __USE_MISC
00521 /* Register a function to be called with the status
00522    given to `exit' and the given argument.  */
00523 extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg)
00524      __THROW __nonnull ((1));
00525 #endif
00526 
00527 __BEGIN_NAMESPACE_STD
00528 /* Call all functions registered with `atexit' and `on_exit',
00529    in the reverse of the order in which they were registered
00530    perform stdio cleanup, and terminate program execution with STATUS.  */
00531 extern void exit (int __status) __THROW __attribute__ ((__noreturn__));
00532 __END_NAMESPACE_STD
00533 
00534 #ifdef __USE_ISOC99
00535 __BEGIN_NAMESPACE_C99
00536 /* Terminate the program with STATUS without calling any of the
00537    functions registered with `atexit' or `on_exit'.  */
00538 extern void _Exit (int __status) __THROW __attribute__ ((__noreturn__));
00539 __END_NAMESPACE_C99
00540 #endif
00541 
00542 
00543 __BEGIN_NAMESPACE_STD
00544 /* Return the value of envariable NAME, or NULL if it doesn't exist.  */
00545 extern char *getenv (__const char *__name) __THROW __nonnull ((1)) __wur;
00546 __END_NAMESPACE_STD
00547 
00548 /* This function is similar to the above but returns NULL if the
00549    programs is running with SUID or SGID enabled.  */
00550 extern char *__secure_getenv (__const char *__name)
00551      __THROW __nonnull ((1)) __wur;
00552 
00553 #if defined __USE_SVID || defined __USE_XOPEN
00554 /* The SVID says this is in <stdio.h>, but this seems a better place. */
00555 /* Put STRING, which is of the form "NAME=VALUE", in the environment.
00556    If there is no `=', remove NAME from the environment.  */
00557 extern int putenv (char *__string) __THROW __nonnull ((1));
00558 #endif
00559 
00560 #if defined __USE_BSD || defined __USE_XOPEN2K
00561 /* Set NAME to VALUE in the environment.
00562    If REPLACE is nonzero, overwrite an existing value.  */
00563 extern int setenv (__const char *__name, __const char *__value, int __replace)
00564      __THROW __nonnull ((2));
00565 
00566 /* Remove the variable NAME from the environment.  */
00567 extern int unsetenv (__const char *__name) __THROW;
00568 #endif
00569 
00570 #ifdef __USE_MISC
00571 /* The `clearenv' was planned to be added to POSIX.1 but probably
00572    never made it.  Nevertheless the POSIX.9 standard (POSIX bindings
00573    for Fortran 77) requires this function.  */
00574 extern int clearenv (void) __THROW;
00575 #endif
00576 
00577 
00578 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
00579 /* Generate a unique temporary file name from TEMPLATE.
00580    The last six characters of TEMPLATE must be "XXXXXX";
00581    they are replaced with a string that makes the file name unique.
00582    Returns TEMPLATE, or a null pointer if it cannot get a unique file name.  */
00583 extern char *mktemp (char *__template) __THROW __nonnull ((1)) __wur;
00584 
00585 /* Generate a unique temporary file name from TEMPLATE.
00586    The last six characters of TEMPLATE must be "XXXXXX";
00587    they are replaced with a string that makes the filename unique.
00588    Returns a file descriptor open on the file for reading and writing,
00589    or -1 if it cannot create a uniquely-named file.
00590 
00591    This function is a possible cancellation points and therefore not
00592    marked with __THROW.  */
00593 # ifndef __USE_FILE_OFFSET64
00594 extern int mkstemp (char *__template) __nonnull ((1)) __wur;
00595 # else
00596 #  ifdef __REDIRECT
00597 extern int __REDIRECT (mkstemp, (char *__template), mkstemp64)
00598      __nonnull ((1)) __wur;
00599 #  else
00600 #   define mkstemp mkstemp64
00601 #  endif
00602 # endif
00603 # ifdef __USE_LARGEFILE64
00604 extern int mkstemp64 (char *__template) __nonnull ((1)) __wur;
00605 # endif
00606 #endif
00607 
00608 #ifdef __USE_BSD
00609 /* Create a unique temporary directory from TEMPLATE.
00610    The last six characters of TEMPLATE must be "XXXXXX";
00611    they are replaced with a string that makes the directory name unique.
00612    Returns TEMPLATE, or a null pointer if it cannot get a unique name.
00613    The directory is created mode 700.  */
00614 extern char *mkdtemp (char *__template) __THROW __nonnull ((1)) __wur;
00615 #endif
00616 
00617 #ifdef __USE_GNU
00618 /* Generate a unique temporary file name from TEMPLATE similar to
00619    mkstemp.  But allow the caller to pass additional flags which are
00620    used in the open call to create the file..
00621 
00622    This function is a possible cancellation points and therefore not
00623    marked with __THROW.  */
00624 # ifndef __USE_FILE_OFFSET64
00625 extern int mkostemp (char *__template, int __flags) __nonnull ((1)) __wur;
00626 # else
00627 #  ifdef __REDIRECT
00628 extern int __REDIRECT (mkostemp, (char *__template, int __flags), mkostemp64)
00629      __nonnull ((1)) __wur;
00630 #  else
00631 #   define mkostemp mkostemp64
00632 #  endif
00633 # endif
00634 # ifdef __USE_LARGEFILE64
00635 extern int mkostemp64 (char *__template, int __flags) __nonnull ((1)) __wur;
00636 # endif
00637 #endif
00638 
00639 
00640 __BEGIN_NAMESPACE_STD
00641 /* Execute the given line as a shell command.
00642 
00643    This function is a cancellation point and therefore not marked with
00644    __THROW.  */
00645 extern int system (__const char *__command) __wur;
00646 __END_NAMESPACE_STD
00647 
00648 
00649 #ifdef __USE_GNU
00650 /* Return a malloc'd string containing the canonical absolute name of the
00651    existing named file.  */
00652 extern char *canonicalize_file_name (__const char *__name)
00653      __THROW __nonnull ((1)) __wur;
00654 #endif
00655 
00656 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
00657 /* Return the canonical absolute name of file NAME.  If RESOLVED is
00658    null, the result is malloc'd; otherwise, if the canonical name is
00659    PATH_MAX chars or more, returns null with `errno' set to
00660    ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars,
00661    returns the name in RESOLVED.  */
00662 extern char *realpath (__const char *__restrict __name,
00663                      char *__restrict __resolved) __THROW __wur;
00664 #endif
00665 
00666 
00667 /* Shorthand for type of comparison functions.  */
00668 #ifndef __COMPAR_FN_T
00669 # define __COMPAR_FN_T
00670 typedef int (*__compar_fn_t) (__const void *, __const void *);
00671 
00672 # ifdef       __USE_GNU
00673 typedef __compar_fn_t comparison_fn_t;
00674 # endif
00675 #endif
00676 #ifdef __USE_GNU
00677 typedef int (*__compar_d_fn_t) (__const void *, __const void *, void *);
00678 #endif
00679 
00680 __BEGIN_NAMESPACE_STD
00681 /* Do a binary search for KEY in BASE, which consists of NMEMB elements
00682    of SIZE bytes each, using COMPAR to perform the comparisons.  */
00683 extern void *bsearch (__const void *__key, __const void *__base,
00684                     size_t __nmemb, size_t __size, __compar_fn_t __compar)
00685      __nonnull ((1, 2, 5)) __wur;
00686 
00687 /* Sort NMEMB elements of BASE, of SIZE bytes each,
00688    using COMPAR to perform the comparisons.  */
00689 extern void qsort (void *__base, size_t __nmemb, size_t __size,
00690                  __compar_fn_t __compar) __nonnull ((1, 4));
00691 #ifdef __USE_GNU
00692 extern void qsort_r (void *__base, size_t __nmemb, size_t __size,
00693                    __compar_d_fn_t __compar, void *__arg)
00694   __nonnull ((1, 4));
00695 #endif
00696 
00697 
00698 /* Return the absolute value of X.  */
00699 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
00700 extern long int labs (long int __x) __THROW __attribute__ ((__const__)) __wur;
00701 __END_NAMESPACE_STD
00702 
00703 #ifdef __USE_ISOC99
00704 __extension__ extern long long int llabs (long long int __x)
00705      __THROW __attribute__ ((__const__)) __wur;
00706 #endif
00707 
00708 
00709 __BEGIN_NAMESPACE_STD
00710 /* Return the `div_t', `ldiv_t' or `lldiv_t' representation
00711    of the value of NUMER over DENOM. */
00712 /* GCC may have built-ins for these someday.  */
00713 extern div_t div (int __numer, int __denom)
00714      __THROW __attribute__ ((__const__)) __wur;
00715 extern ldiv_t ldiv (long int __numer, long int __denom)
00716      __THROW __attribute__ ((__const__)) __wur;
00717 __END_NAMESPACE_STD
00718 
00719 #ifdef __USE_ISOC99
00720 __BEGIN_NAMESPACE_C99
00721 __extension__ extern lldiv_t lldiv (long long int __numer,
00722                                 long long int __denom)
00723      __THROW __attribute__ ((__const__)) __wur;
00724 __END_NAMESPACE_C99
00725 #endif
00726 
00727 
00728 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED
00729 /* Convert floating point numbers to strings.  The returned values are
00730    valid only until another call to the same function.  */
00731 
00732 /* Convert VALUE to a string with NDIGIT digits and return a pointer to
00733    this.  Set *DECPT with the position of the decimal character and *SIGN
00734    with the sign of the number.  */
00735 extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt,
00736                  int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur;
00737 
00738 /* Convert VALUE to a string rounded to NDIGIT decimal digits.  Set *DECPT
00739    with the position of the decimal character and *SIGN with the sign of
00740    the number.  */
00741 extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt,
00742                  int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur;
00743 
00744 /* If possible convert VALUE to a string with NDIGIT significant digits.
00745    Otherwise use exponential representation.  The resulting string will
00746    be written to BUF.  */
00747 extern char *gcvt (double __value, int __ndigit, char *__buf)
00748      __THROW __nonnull ((3)) __wur;
00749 
00750 
00751 # ifdef __USE_MISC
00752 /* Long double versions of above functions.  */
00753 extern char *qecvt (long double __value, int __ndigit,
00754                   int *__restrict __decpt, int *__restrict __sign)
00755      __THROW __nonnull ((3, 4)) __wur;
00756 extern char *qfcvt (long double __value, int __ndigit,
00757                   int *__restrict __decpt, int *__restrict __sign)
00758      __THROW __nonnull ((3, 4)) __wur;
00759 extern char *qgcvt (long double __value, int __ndigit, char *__buf)
00760      __THROW __nonnull ((3)) __wur;
00761 
00762 
00763 /* Reentrant version of the functions above which provide their own
00764    buffers.  */
00765 extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt,
00766                  int *__restrict __sign, char *__restrict __buf,
00767                  size_t __len) __THROW __nonnull ((3, 4, 5));
00768 extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt,
00769                  int *__restrict __sign, char *__restrict __buf,
00770                  size_t __len) __THROW __nonnull ((3, 4, 5));
00771 
00772 extern int qecvt_r (long double __value, int __ndigit,
00773                   int *__restrict __decpt, int *__restrict __sign,
00774                   char *__restrict __buf, size_t __len)
00775      __THROW __nonnull ((3, 4, 5));
00776 extern int qfcvt_r (long double __value, int __ndigit,
00777                   int *__restrict __decpt, int *__restrict __sign,
00778                   char *__restrict __buf, size_t __len)
00779      __THROW __nonnull ((3, 4, 5));
00780 # endif       /* misc */
00781 #endif /* use MISC || use X/Open Unix */
00782 
00783 
00784 __BEGIN_NAMESPACE_STD
00785 /* Return the length of the multibyte character
00786    in S, which is no longer than N.  */
00787 extern int mblen (__const char *__s, size_t __n) __THROW __wur;
00788 /* Return the length of the given multibyte character,
00789    putting its `wchar_t' representation in *PWC.  */
00790 extern int mbtowc (wchar_t *__restrict __pwc,
00791                  __const char *__restrict __s, size_t __n) __THROW __wur;
00792 /* Put the multibyte character represented
00793    by WCHAR in S, returning its length.  */
00794 extern int wctomb (char *__s, wchar_t __wchar) __THROW __wur;
00795 
00796 
00797 /* Convert a multibyte string to a wide char string.  */
00798 extern size_t mbstowcs (wchar_t *__restrict  __pwcs,
00799                      __const char *__restrict __s, size_t __n) __THROW;
00800 /* Convert a wide char string to multibyte string.  */
00801 extern size_t wcstombs (char *__restrict __s,
00802                      __const wchar_t *__restrict __pwcs, size_t __n)
00803      __THROW;
00804 __END_NAMESPACE_STD
00805 
00806 
00807 #ifdef __USE_SVID
00808 /* Determine whether the string value of RESPONSE matches the affirmation
00809    or negative response expression as specified by the LC_MESSAGES category
00810    in the program's current locale.  Returns 1 if affirmative, 0 if
00811    negative, and -1 if not matching.  */
00812 extern int rpmatch (__const char *__response) __THROW __nonnull ((1)) __wur;
00813 #endif
00814 
00815 
00816 #ifdef __USE_XOPEN_EXTENDED
00817 /* Parse comma separated suboption from *OPTIONP and match against
00818    strings in TOKENS.  If found return index and set *VALUEP to
00819    optional value introduced by an equal sign.  If the suboption is
00820    not part of TOKENS return in *VALUEP beginning of unknown
00821    suboption.  On exit *OPTIONP is set to the beginning of the next
00822    token or at the terminating NUL character.  */
00823 extern int getsubopt (char **__restrict __optionp,
00824                     char *__const *__restrict __tokens,
00825                     char **__restrict __valuep)
00826      __THROW __nonnull ((1, 2, 3)) __wur;
00827 #endif
00828 
00829 
00830 #ifdef __USE_XOPEN
00831 /* Setup DES tables according KEY.  */
00832 extern void setkey (__const char *__key) __THROW __nonnull ((1));
00833 #endif
00834 
00835 
00836 /* X/Open pseudo terminal handling.  */
00837 
00838 #ifdef __USE_XOPEN2K
00839 /* Return a master pseudo-terminal handle.  */
00840 extern int posix_openpt (int __oflag) __wur;
00841 #endif
00842 
00843 #ifdef __USE_XOPEN
00844 /* The next four functions all take a master pseudo-tty fd and
00845    perform an operation on the associated slave:  */
00846 
00847 /* Chown the slave to the calling user.  */
00848 extern int grantpt (int __fd) __THROW;
00849 
00850 /* Release an internal lock so the slave can be opened.
00851    Call after grantpt().  */
00852 extern int unlockpt (int __fd) __THROW;
00853 
00854 /* Return the pathname of the pseudo terminal slave assoicated with
00855    the master FD is open on, or NULL on errors.
00856    The returned storage is good until the next call to this function.  */
00857 extern char *ptsname (int __fd) __THROW __wur;
00858 #endif
00859 
00860 #ifdef __USE_GNU
00861 /* Store at most BUFLEN characters of the pathname of the slave pseudo
00862    terminal associated with the master FD is open on in BUF.
00863    Return 0 on success, otherwise an error number.  */
00864 extern int ptsname_r (int __fd, char *__buf, size_t __buflen)
00865      __THROW __nonnull ((2));
00866 
00867 /* Open a master pseudo terminal and return its file descriptor.  */
00868 extern int getpt (void);
00869 #endif
00870 
00871 #ifdef __USE_BSD
00872 /* Put the 1 minute, 5 minute and 15 minute load averages into the first
00873    NELEM elements of LOADAVG.  Return the number written (never more than
00874    three, but may be less than NELEM), or -1 if an error occurred.  */
00875 extern int getloadavg (double __loadavg[], int __nelem)
00876      __THROW __nonnull ((1));
00877 #endif
00878 
00879 
00880 /* Define some macros helping to catch buffer overflows.  */
00881 #if __USE_FORTIFY_LEVEL > 0 && defined __extern_always_inline
00882 # include <bits/stdlib.h>
00883 #endif
00884 #ifdef __LDBL_COMPAT
00885 # include <bits/stdlib-ldbl.h>
00886 #endif
00887 
00888 #endif /* don't just need malloc and calloc */
00889 #undef __need_malloc_and_calloc
00890 
00891 __END_DECLS
00892 
00893 #endif /* stdlib.h  */