stdlib.h revision 1.39
1/* $OpenBSD: stdlib.h,v 1.39 2006/09/17 16:48:04 djm Exp $ */ 2/* $NetBSD: stdlib.h,v 1.25 1995/12/27 21:19:08 jtc Exp $ */ 3 4/*- 5 * Copyright (c) 1990 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the University nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * @(#)stdlib.h 5.13 (Berkeley) 6/4/91 33 */ 34 35#ifndef _STDLIB_H_ 36#define _STDLIB_H_ 37 38#include <sys/cdefs.h> 39#include <machine/_types.h> 40#if __BSD_VISIBLE /* for quad_t, etc. (XXX - use protected types) */ 41#include <sys/types.h> 42#endif 43 44#ifndef _SIZE_T_DEFINED_ 45#define _SIZE_T_DEFINED_ 46typedef __size_t size_t; 47#endif 48 49/* in C++, wchar_t is a built-in type */ 50#if !defined(_WCHAR_T_DEFINED_) && !defined(__cplusplus) 51#define _WCHAR_T_DEFINED_ 52typedef __wchar_t wchar_t; 53#endif 54 55typedef struct { 56 int quot; /* quotient */ 57 int rem; /* remainder */ 58} div_t; 59 60typedef struct { 61 long quot; /* quotient */ 62 long rem; /* remainder */ 63} ldiv_t; 64 65#if __ISO_C_VISIBLE >= 1999 66typedef struct { 67 long long quot; /* quotient */ 68 long long rem; /* remainder */ 69} lldiv_t; 70#endif 71 72#if __BSD_VISIBLE 73typedef struct { 74 quad_t quot; /* quotient */ 75 quad_t rem; /* remainder */ 76} qdiv_t; 77#endif 78 79 80#ifndef NULL 81#ifdef __GNUG__ 82#define NULL __null 83#else 84#define NULL 0L 85#endif 86#endif 87 88#define EXIT_FAILURE 1 89#define EXIT_SUCCESS 0 90 91#define RAND_MAX 0x7fffffff 92 93extern size_t __mb_cur_max; 94#define MB_CUR_MAX __mb_cur_max 95 96#include <sys/cdefs.h> 97 98/* 99 * Some header files may define an abs macro. 100 * If defined, undef it to prevent a syntax error and issue a warning. 101 */ 102#ifdef abs 103#undef abs 104#warning abs macro collides with abs() prototype, undefining 105#endif 106 107__BEGIN_DECLS 108__dead void abort(void); 109int abs(int); 110int atexit(void (*)(void)); 111double atof(const char *); 112int atoi(const char *); 113long atol(const char *); 114void *bsearch(const void *, const void *, size_t, size_t, 115 int (*)(const void *, const void *)); 116void *calloc(size_t, size_t); 117div_t div(int, int); 118char *ecvt(double, int, int *, int *); 119__dead void exit(int); 120__dead void _Exit(int); 121char *fcvt(double, int, int *, int *); 122void free(void *); 123char *gcvt(double, int, char *); 124char *getenv(const char *); 125long labs(long); 126ldiv_t ldiv(long, long); 127void *malloc(size_t); 128void qsort(void *, size_t, size_t, int (*)(const void *, const void *)); 129int rand(void); 130void *realloc(void *, size_t); 131void srand(unsigned); 132double strtod(const char *, char **); 133long strtol(const char *, char **, int); 134unsigned long 135 strtoul(const char *, char **, int); 136int system(const char *); 137 138/* these are currently just stubs */ 139int mblen(const char *, size_t); 140size_t mbstowcs(wchar_t *, const char *, size_t); 141int wctomb(char *, wchar_t); 142int mbtowc(wchar_t *, const char *, size_t); 143size_t wcstombs(char *, const wchar_t *, size_t); 144 145/* 146 * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2 147 */ 148#if __BSD_VISIBLE || __POSIX_VISIBLE >= 199506 || __XPG_VISIBLE >= 500 || \ 149 defined(_REENTRANT) 150int rand_r(unsigned int *); 151#endif 152 153#if __BSD_VISIBLE || __XPG_VISIBLE >= 400 154double drand48(void); 155double erand48(unsigned short[3]); 156long jrand48(unsigned short[3]); 157void lcong48(unsigned short[7]); 158long lrand48(void); 159long mrand48(void); 160long nrand48(unsigned short[3]); 161unsigned short *seed48(unsigned short[3]); 162void srand48(long); 163 164int putenv(const char *); 165#endif 166 167#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 168long a64l(const char *); 169char *l64a(long); 170 171char *initstate(unsigned int, char *, size_t) 172 __attribute__((__bounded__ (__string__,2,3))); 173long random(void); 174char *setstate(const char *); 175void srandom(unsigned int); 176 177int mkstemp(char *); 178char *mktemp(char *); 179 180char *realpath(const char *, char *); 181 182int setkey(const char *); 183 184int ttyslot(void); 185 186void *valloc(size_t); /* obsoleted by malloc() */ 187#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */ 188 189/* 190 * ISO C99 191 */ 192#if __ISO_C_VISIBLE >= 1999 193long long 194 atoll(const char *); 195long long 196 llabs(long long); 197lldiv_t 198 lldiv(long long, long long); 199long long 200 strtoll(const char *, char **, int); 201unsigned long long 202 strtoull(const char *, char **, int); 203#endif 204 205/* 206 * The Open Group Base Specifications, Issue 6; IEEE Std 1003.1-2001 (POSIX) 207 */ 208#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XPG_VISIBLE >= 600 209int setenv(const char *, const char *, int); 210void unsetenv(const char *); 211#endif 212 213#if __BSD_VISIBLE 214#if defined(alloca) && (alloca == __builtin_alloca) && (__GNUC__ < 2) 215void *alloca(int); /* built-in for gcc */ 216#else 217void *alloca(size_t); 218#endif /* __GNUC__ */ 219 220char *getbsize(int *, long *); 221char *cgetcap(char *, const char *, int); 222int cgetclose(void); 223int cgetent(char **, char **, const char *); 224int cgetfirst(char **, char **); 225int cgetmatch(char *, const char *); 226int cgetnext(char **, char **); 227int cgetnum(char *, const char *, long *); 228int cgetset(const char *); 229int cgetusedb(int); 230int cgetstr(char *, const char *, char **); 231int cgetustr(char *, const char *, char **); 232 233int daemon(int, int); 234char *devname(int, mode_t); 235int getloadavg(double [], int); 236 237void cfree(void *); 238 239#ifndef _GETOPT_DEFINED_ 240#define _GETOPT_DEFINED_ 241int getopt(int, char * const *, const char *); 242extern char *optarg; /* getopt(3) external variables */ 243extern int opterr, optind, optopt, optreset; 244int getsubopt(char **, char * const *, char **); 245extern char *suboptarg; /* getsubopt(3) external variable */ 246#endif /* _GETOPT_DEFINED_ */ 247 248char *mkdtemp(char *); 249int mkstemps(char *, int); 250 251int heapsort(void *, size_t, size_t, int (*)(const void *, const void *)); 252int mergesort(void *, size_t, size_t, int (*)(const void *, const void *)); 253int radixsort(const unsigned char **, int, const unsigned char *, 254 unsigned); 255int sradixsort(const unsigned char **, int, const unsigned char *, 256 unsigned); 257 258void srandomdev(void); 259long long 260 strtonum(const char *, long long, long long, const char **); 261 262void setproctitle(const char *, ...) 263 __attribute__((__format__ (__printf__, 1, 2))); 264 265quad_t qabs(quad_t); 266qdiv_t qdiv(quad_t, quad_t); 267quad_t strtoq(const char *, char **, int); 268u_quad_t strtouq(const char *, char **, int); 269 270u_int32_t arc4random(void); 271void arc4random_stir(void); 272void arc4random_addrandom(unsigned char *, int) 273 __attribute__((__bounded__ (__string__,1,2))); 274#endif /* __BSD_VISIBLE */ 275 276__END_DECLS 277 278#endif /* _STDLIB_H_ */ 279