stdlib.h revision 1.25
1/* $OpenBSD: stdlib.h,v 1.25 2003/06/02 19:34:12 millert 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#include <machine/ansi.h> 38 39#if !defined(_ANSI_SOURCE) /* for quad_t, etc. */ 40#include <sys/types.h> 41#endif 42 43#ifdef _BSD_SIZE_T_ 44typedef _BSD_SIZE_T_ size_t; 45#undef _BSD_SIZE_T_ 46#endif 47 48#ifdef _BSD_WCHAR_T_ 49/* in C++, wchar_t is a built-in type */ 50#ifndef __cplusplus 51typedef _BSD_WCHAR_T_ wchar_t; 52#endif 53#undef _BSD_WCHAR_T_ 54#endif 55 56typedef struct { 57 int quot; /* quotient */ 58 int rem; /* remainder */ 59} div_t; 60 61typedef struct { 62 long quot; /* quotient */ 63 long rem; /* remainder */ 64} ldiv_t; 65 66#if !defined(_ANSI_SOURCE) 67typedef struct { 68 quad_t quot; /* quotient */ 69 quad_t rem; /* remainder */ 70} qdiv_t; 71#endif 72 73 74#ifndef NULL 75#ifdef __GNUG__ 76#define NULL __null 77#else 78#define NULL 0L 79#endif 80#endif 81 82#define EXIT_FAILURE 1 83#define EXIT_SUCCESS 0 84 85#define RAND_MAX 0x7fffffff 86 87#define MB_CUR_MAX 1 /* XXX */ 88 89#include <sys/cdefs.h> 90 91/* 92 * Some header files may define an abs macro. 93 * If defined, undef it to prevent a syntax error and issue a warning. 94 */ 95#ifdef abs 96#undef abs 97#warning abs macro collides with abs() prototype, undefining 98#endif 99 100__BEGIN_DECLS 101__dead void abort(void); 102int abs(int); 103int atexit(void (*)(void)); 104double atof(const char *); 105int atoi(const char *); 106long atol(const char *); 107long long atoll(const char *); 108void *bsearch(const void *, const void *, size_t, size_t, 109 int (*)(const void *, const void *)); 110void *calloc(size_t, size_t); 111div_t div(int, int); 112char *ecvt(double, int, int *, int *); 113__dead void exit(int); 114char *fcvt(double, int, int *, int *); 115void free(void *); 116char *gcvt(double, int, char *); 117char *getenv(const char *); 118long labs(long); 119ldiv_t ldiv(long, long); 120void *malloc(size_t); 121void qsort(void *, size_t, size_t, int (*)(const void *, const void *)); 122int rand(void); 123int rand_r(unsigned int *); 124void *realloc(void *, size_t); 125void srand(unsigned); 126double strtod(const char *, char **); 127long strtol(const char *, char **, int); 128long long 129 strtoll(const char *, char **, int); 130unsigned long 131 strtoul(const char *, char **, int); 132unsigned long long 133 strtoull(const char *, char **, int); 134int system(const char *); 135 136/* these are currently just stubs */ 137int mblen(const char *, size_t); 138size_t mbstowcs(wchar_t *, const char *, size_t); 139int wctomb(char *, wchar_t); 140int mbtowc(wchar_t *, const char *, size_t); 141size_t wcstombs(char *, const wchar_t *, size_t); 142 143#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 144#if defined(alloca) && (alloca == __builtin_alloca) && (__GNUC__ < 2) 145void *alloca(int); /* built-in for gcc */ 146#else 147void *alloca(size_t); 148#endif /* __GNUC__ */ 149 150char *getbsize(int *, long *); 151char *cgetcap(char *, const char *, int); 152int cgetclose(void); 153int cgetent(char **, char **, const char *); 154int cgetfirst(char **, char **); 155int cgetmatch(char *, const char *); 156int cgetnext(char **, char **); 157int cgetnum(char *, const char *, long *); 158int cgetset(const char *); 159int cgetusedb(int); 160int cgetstr(char *, const char *, char **); 161int cgetustr(char *, const char *, char **); 162 163int daemon(int, int); 164char *devname(int, int); 165int getloadavg(double [], int); 166 167long a64l(const char *); 168char *l64a(long); 169 170void cfree(void *); 171 172#ifndef _GETOPT_DEFINED_ 173#define _GETOPT_DEFINED_ 174int getopt(int, char * const *, const char *); 175extern char *optarg; /* getopt(3) external variables */ 176extern int opterr; 177extern int optind; 178extern int optopt; 179extern int optreset; 180int getsubopt(char **, char * const *, char **); 181extern char *suboptarg; /* getsubopt(3) external variable */ 182#endif /* _GETOPT_DEFINED_ */ 183 184int heapsort(void *, size_t, size_t, int (*)(const void *, const void *)); 185int mergesort(void *, size_t, size_t, int (*)(const void *, const void *)); 186int radixsort(const unsigned char **, int, const unsigned char *, 187 unsigned); 188int sradixsort(const unsigned char **, int, const unsigned char *, 189 unsigned); 190 191char *initstate(unsigned int, char *, size_t); 192long random(void); 193char *realpath(const char *, char *); 194char *setstate(const char *); 195void srandom(unsigned int); 196void srandomdev(void); 197 198int putenv(const char *); 199int setenv(const char *, const char *, int); 200void unsetenv(const char *); 201void setproctitle(const char *, ...) 202 __attribute__((__format__ (__printf__, 1, 2))); 203 204quad_t qabs(quad_t); 205qdiv_t qdiv(quad_t, quad_t); 206quad_t strtoq(const char *, char **, int); 207u_quad_t strtouq(const char *, char **, int); 208 209double drand48(void); 210double erand48(unsigned short[3]); 211long jrand48(unsigned short[3]); 212void lcong48(unsigned short[7]); 213long lrand48(void); 214long mrand48(void); 215long nrand48(unsigned short[3]); 216unsigned short *seed48(unsigned short[3]); 217void srand48(long); 218 219u_int32_t arc4random(void); 220void arc4random_stir(void); 221void arc4random_addrandom(unsigned char *, int); 222#endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */ 223 224__END_DECLS 225 226#endif /* _STDLIB_H_ */ 227