Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

stdlib.h

00001 /*-
00002  * Copyright (c) 1990, 1993
00003  *      The Regents of the University of California.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. All advertising materials mentioning features or use of this software
00014  *    must display the following acknowledgement:
00015  *      This product includes software developed by the University of
00016  *      California, Berkeley and its contributors.
00017  * 4. Neither the name of the University nor the names of its contributors
00018  *    may be used to endorse or promote products derived from this software
00019  *    without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00022  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00025  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00026  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00027  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00028  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00030  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  *
00033  *      @(#)stdlib.h    8.5 (Berkeley) 5/19/95
00034  * $FreeBSD: src/include/stdlib.h,v 1.54 2003/06/25 19:06:40 obrien Exp $
00035  */
00036 
00037 #ifndef _STDLIB_H_
00038 #define _STDLIB_H_
00039 
00040 #include <sys/cdefs.h>
00041 #include <sys/_types.h>
00042 
00043 #if __BSD_VISIBLE
00044 #ifndef _RUNE_T_DECLARED
00045 typedef __rune_t        rune_t;
00046 #define _RUNE_T_DECLARED
00047 #endif
00048 #endif
00049 
00050 #ifndef _SIZE_T_DECLARED
00051 #if 1
00052 #include <stddef.h>
00053 #else
00054 typedef __size_t        size_t;
00055 #endif
00056 #define _SIZE_T_DECLARED
00057 #endif
00058 
00059 #ifdef HAVE_WCHAR
00060 #ifndef __cplusplus
00061 #ifndef _WCHAR_T_DECLARED
00062 typedef __wchar_t       wchar_t;
00063 #define _WCHAR_T_DECLARED
00064 #endif
00065 #endif
00066 #endif
00067 
00068 typedef struct {
00069         int     quot;           /* quotient */
00070         int     rem;            /* remainder */
00071 } div_t;
00072 
00073 typedef struct {
00074         long    quot;
00075         long    rem;
00076 } ldiv_t;
00077 
00078 #ifndef NULL
00079 #define NULL    0
00080 #endif
00081 
00082 #define EXIT_FAILURE    1
00083 #define EXIT_SUCCESS    0
00084 
00085 #define RAND_MAX        0x7fffffff
00086 
00087 extern int __mb_cur_max;
00088 #define MB_CUR_MAX      __mb_cur_max
00089 
00090 __BEGIN_DECLS
00091 void     abort(void) __dead2;
00092 int      abs(int) __pure2;
00093 int      atexit(void (*)(void));
00094 double   atof(const char *);
00095 int      atoi(const char *);
00096 long     atol(const char *);
00097 void    *bsearch(const void *, const void *, size_t,
00098             size_t, int (*)(const void *, const void *));
00099 void    *calloc(size_t, size_t);
00100 div_t    div(int, int) __pure2;
00101 void     exit(int) __dead2;
00102 void     free(void *);
00103 char    *getenv(const char *);
00104 long     labs(long) __pure2;
00105 ldiv_t   ldiv(long, long) __pure2;
00106 void    *malloc(size_t);
00107 #ifdef HAVE_WCHAR
00108 int      mblen(const char *, size_t);
00109 size_t   mbstowcs(wchar_t * __restrict , const char * __restrict, size_t);
00110 int      mbtowc(wchar_t * __restrict, const char * __restrict, size_t);
00111 #endif
00112 void     qsort(void *, size_t, size_t,
00113             int (*)(const void *, const void *));
00114 int      rand(void);
00115 void    *realloc(void *, size_t);
00116 void     srand(unsigned);
00117 double   strtod(const char * __restrict, char ** __restrict);
00118 float    strtof(const char * __restrict, char ** __restrict);
00119 long     strtol(const char * __restrict, char ** __restrict, int);
00120 long double
00121          strtold(const char * __restrict, char ** __restrict);
00122 unsigned long
00123          strtoul(const char * __restrict, char ** __restrict, int);
00124 #ifdef HAVE_OS
00125 int      system(const char *);
00126 #endif
00127 #ifdef HAVE_WCHAR
00128 int      wctomb(char *, wchar_t);
00129 size_t   wcstombs(char * __restrict, const wchar_t * __restrict, size_t);
00130 #endif
00131 
00132 /*
00133  * Functions added in C99 which we make conditionally available in the
00134  * BSD^C89 namespace if the compiler supports `long long'.
00135  * The #if test is more complicated than it ought to be because
00136  * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long'
00137  * is not supported in the compilation environment (which therefore means
00138  * that it can't really be ISO C99).
00139  *
00140  * (The only other extension made by C99 in thie header is _Exit().)
00141  */
00142 #if __ISO_C_VISIBLE >= 1999
00143 #ifdef __LONG_LONG_SUPPORTED
00144 /* LONGLONG */
00145 typedef struct {
00146         long long quot;
00147         long long rem;
00148 } lldiv_t;
00149 
00150 /* LONGLONG */
00151 long long
00152          atoll(const char *);
00153 /* LONGLONG */
00154 long long
00155          llabs(long long) __pure2;
00156 /* LONGLONG */
00157 lldiv_t  lldiv(long long, long long) __pure2;
00158 /* LONGLONG */
00159 long long
00160          strtoll(const char * __restrict, char ** __restrict, int);
00161 /* LONGLONG */
00162 unsigned long long
00163          strtoull(const char * __restrict, char ** __restrict, int);
00164 #endif /* __LONG_LONG_SUPPORTED */
00165 
00166 void     _Exit(int) __dead2;
00167 #endif /* __ISO_C_VISIBLE >= 1999 */
00168 
00169 /*
00170  * Extensions made by POSIX relative to C.  We don't know yet which edition
00171  * of POSIX made these extensions, so assume they've always been there until
00172  * research can be done.
00173  */
00174 #if __POSIX_VISIBLE /* >= ??? */
00175 /* int   posix_memalign(void **, size_t, size_t); (ADV) */
00176 int      rand_r(unsigned *);                    /* (TSF) */
00177 int      setenv(const char *, const char *, int);
00178 void     unsetenv(const char *);
00179 #endif
00180 
00181 /*
00182  * The only changes to the XSI namespace in revision 6 were the deletion
00183  * of the ttyslot() and valloc() functions, which FreeBSD never declared
00184  * in this header.  For revision 7, ecvt(), fcvt(), and gcvt(), which
00185  * FreeBSD also does not have, and mktemp(), are to be deleted.
00186  */
00187 #if __XSI_VISIBLE
00188 /* XXX XSI requires pollution from <sys/wait.h> here.  We'd rather not. */
00189 /* long  a64l(const char *); */
00190 double   drand48(void);
00191 /* char *ecvt(double, int, int * __restrict, int * __restrict); */
00192 double   erand48(unsigned short[3]);
00193 /* char *fcvt(double, int, int * __restrict, int * __restrict); */
00194 /* char *gcvt(double, int, int * __restrict, int * __restrict); */
00195 #ifndef _GETSUBOPT_DECLARED
00196 int      getsubopt(char **, char *const *, char **);
00197 #define _GETSUBOPT_DECLARED
00198 #endif
00199 int      grantpt(int);
00200 char    *initstate(unsigned long /* XSI requires u_int */, char *, long);
00201 long     jrand48(unsigned short[3]);
00202 /* char *l64a(long); */
00203 void     lcong48(unsigned short[7]);
00204 long     lrand48(void);
00205 #ifndef _MKSTEMP_DECLARED
00206 int      mkstemp(char *);
00207 #define _MKSTEMP_DECLARED
00208 #endif
00209 #ifndef _MKTEMP_DECLARED
00210 char    *mktemp(char *);
00211 #define _MKTEMP_DECLARED
00212 #endif
00213 long     mrand48(void);
00214 long     nrand48(unsigned short[3]);
00215 int      posix_openpt(int);
00216 char    *ptsname(int);
00217 int      putenv(const char *);
00218 long     random(void);
00219 char    *realpath(const char *, char resolved_path[]);
00220 unsigned short
00221         *seed48(unsigned short[3]);
00222 #ifndef _SETKEY_DECLARED
00223 int      setkey(const char *);
00224 #define _SETKEY_DECLARED
00225 #endif
00226 char    *setstate(/* const */ char *);
00227 void     srand48(long);
00228 void     srandom(unsigned long);
00229 int      unlockpt(int);
00230 #endif /* __XSI_VISIBLE */
00231 
00232 #if __BSD_VISIBLE
00233 extern const char *_malloc_options;
00234 extern void (*_malloc_message)(const char *, const char *, const char *,
00235             const char *);
00236 
00237 /*
00238  * The alloca() function can't be implemented in C, and on some
00239  * platforms it can't be implemented at all as a callable function.
00240  * The GNU C compiler provides a built-in alloca() which we can use;
00241  * in all other cases, provide a prototype, mainly to pacify various
00242  * incarnations of lint.  On platforms where alloca() is not in libc,
00243  * programs which use it will fail to link when compiled with non-GNU
00244  * compilers.
00245  */
00246 #if __GNUC__ >= 2 || defined(__INTEL_COMPILER)
00247 #undef  alloca  /* some GNU bits try to get cute and define this on their own */
00248 #define alloca(sz) __builtin_alloca(sz)
00249 #elif defined(lint)
00250 void    *alloca(size_t);
00251 #endif
00252 
00253 __uint32_t
00254          arc4random(void);
00255 void     arc4random_addrandom(unsigned char *dat, int datlen);
00256 void     arc4random_stir(void);
00257 char    *getbsize(int *, long *);
00258                                         /* getcap(3) functions */
00259 char    *cgetcap(char *, const char *, int);
00260 int      cgetclose(void);
00261 int      cgetent(char **, char **, const char *);
00262 int      cgetfirst(char **, char **);
00263 int      cgetmatch(const char *, const char *);
00264 int      cgetnext(char **, char **);
00265 int      cgetnum(char *, const char *, long *);
00266 int      cgetset(const char *);
00267 int      cgetstr(char *, const char *, char **);
00268 int      cgetustr(char *, const char *, char **);
00269 
00270 int      daemon(int, int);
00271 char    *devname(int, int);
00272 char    *devname_r(int, int, char *, int);
00273 int      getloadavg(double [], int);
00274 __const char *
00275          getprogname(void);
00276 
00277 int      heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
00278 int      mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
00279 void     qsort_r(void *, size_t, size_t, void *,
00280             int (*)(void *, const void *, const void *));
00281 int      radixsort(const unsigned char **, int, const unsigned char *,
00282             unsigned);
00283 void    *reallocf(void *, size_t);
00284 void     setprogname(const char *);
00285 int      sradixsort(const unsigned char **, int, const unsigned char *,
00286             unsigned);
00287 void     sranddev(void);
00288 void     srandomdev(void);
00289 
00290 #endif /* __BSD_VISIBLE */
00291 __END_DECLS
00292 
00293 #endif /* !_STDLIB_H_ */