1/* $OpenBSD: stdlib.h,v 1.77 2024/03/01 21:30:40 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 38#include <sys/cdefs.h> 39#include <sys/_null.h> 40#include <machine/_types.h> 41#if __BSD_VISIBLE /* for quad_t, etc. (XXX - use protected types) */ 42#include <sys/types.h> 43#endif 44 45#ifndef _SIZE_T_DEFINED_ 46#define _SIZE_T_DEFINED_ 47typedef __size_t size_t; 48#endif 49 50/* in C++, wchar_t is a built-in type */ 51#if !defined(_WCHAR_T_DEFINED_) && !defined(__cplusplus) 52#define _WCHAR_T_DEFINED_ 53typedef __wchar_t 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 __ISO_C_VISIBLE >= 1999 67typedef struct { 68 long long quot; /* quotient */ 69 long long rem; /* remainder */ 70} lldiv_t; 71#endif 72 73#if __BSD_VISIBLE 74typedef struct { 75 quad_t quot; /* quotient */ 76 quad_t rem; /* remainder */ 77} qdiv_t; 78#endif 79 80#define EXIT_FAILURE 1 81#define EXIT_SUCCESS 0 82 83#define RAND_MAX 0x7fffffff 84 85#define MB_CUR_MAX __mb_cur_max() 86 87/* 88 * Some header files may define an abs macro. 89 * If defined, undef it to prevent a syntax error and issue a warning. 90 */ 91#ifdef abs 92#undef abs 93#warning abs macro collides with abs() prototype, undefining 94#endif 95 96__BEGIN_DECLS 97__dead void abort(void); 98int abs(int); 99int atexit(void (*)(void)); 100double atof(const char *); 101int atoi(const char *); 102long atol(const char *); 103void *bsearch(const void *, const void *, size_t, size_t, 104 int (*)(const void *, const void *)); 105void *calloc(size_t, size_t); 106div_t div(int, int); 107__dead void exit(int); 108__dead void _Exit(int); 109void free(void *); 110char *getenv(const char *); 111long labs(long); 112ldiv_t ldiv(long, long); 113void *malloc(size_t); 114#if __BSD_VISIBLE 115void freezero(void *, size_t) 116 __attribute__ ((__bounded__(__buffer__,1,2))); 117void *calloc_conceal(size_t, size_t); 118void *malloc_conceal(size_t); 119void *reallocarray(void *, size_t, size_t); 120void *recallocarray(void *, size_t, size_t, size_t); 121#endif /* __BSD_VISIBLE */ 122void qsort(void *, size_t, size_t, int (*)(const void *, const void *)); 123int rand(void); 124void *realloc(void *, size_t); 125void srand(unsigned); 126void srand_deterministic(unsigned); 127double strtod(const char *__restrict, char **__restrict); 128float strtof(const char *__restrict, char **__restrict); 129long strtol(const char *__restrict, char **__restrict, int); 130long double 131 strtold(const char *__restrict, char **__restrict); 132unsigned long 133 strtoul(const char *__restrict, char **__restrict, int); 134int system(const char *); 135 136size_t __mb_cur_max(void); 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/* 144 * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2 145 */ 146#if __BSD_VISIBLE || __POSIX_VISIBLE >= 199506 || defined(_REENTRANT) 147int rand_r(unsigned int *); 148#endif 149 150#if __BSD_VISIBLE || __XPG_VISIBLE >= 400 151double drand48(void); 152double erand48(unsigned short[3]); 153long jrand48(unsigned short[3]); 154void lcong48(unsigned short[7]); 155void lcong48_deterministic(unsigned short[7]); 156long lrand48(void); 157long mrand48(void); 158long nrand48(unsigned short[3]); 159unsigned short *seed48(unsigned short[3]); 160unsigned short *seed48_deterministic(unsigned short[3]); 161void srand48(long); 162void srand48_deterministic(long); 163 164int putenv(char *); 165#endif 166 167/* 168 * XSI functions marked LEGACY in IEEE Std 1003.1-2001 (POSIX) and 169 * removed in IEEE Std 1003.1-2008 170 */ 171#if __BSD_VISIBLE || __XPG_VISIBLE < 700 172char *ecvt(double, int, int *, int *); 173char *fcvt(double, int, int *, int *); 174char *gcvt(double, int, char *); 175#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 176char *mktemp(char *); 177#endif 178#endif /* __BSD_VISIBLE || __XPG_VISIBLE < 700 */ 179 180#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 181long a64l(const char *); 182char *l64a(long); 183 184char *initstate(unsigned int, char *, size_t) 185 __attribute__((__bounded__ (__string__,2,3))); 186long random(void); 187char *setstate(char *); 188void srandom(unsigned int); 189void srandom_deterministic(unsigned int); 190 191char *realpath(const char *, char *) 192 __attribute__((__bounded__ (__minbytes__,2,1024))); 193 194/* 195 * XSI functions marked LEGACY in XPG5 and removed in IEEE Std 1003.1-2001 196 */ 197#if __BSD_VISIBLE || __XPG_VISIBLE < 600 198int ttyslot(void); 199void *valloc(size_t); /* obsoleted by malloc() */ 200#endif 201#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */ 202 203/* 204 * 4.4BSD, then XSI in XPG4.2, then added to POSIX base in IEEE Std 1003.1-2008 205 */ 206#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809 207int mkstemp(char *); 208#endif 209 210/* 211 * ISO C99 212 */ 213#if __ISO_C_VISIBLE >= 1999 214long long 215 atoll(const char *); 216long long 217 llabs(long long); 218lldiv_t 219 lldiv(long long, long long); 220long long 221 strtoll(const char *__restrict, char **__restrict, int); 222unsigned long long 223 strtoull(const char *__restrict, char **__restrict, int); 224#endif 225 226#if __ISO_C_VISIBLE >= 2011 227void * 228 aligned_alloc(size_t, size_t); 229#endif 230 231/* 232 * The Open Group Base Specifications, Issue 6; IEEE Std 1003.1-2001 (POSIX) 233 */ 234#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 235int posix_memalign(void **, size_t, size_t); 236int setenv(const char *, const char *, int); 237int unsetenv(const char *); 238#endif 239#if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200112 240char *ptsname(int); 241int grantpt(int); 242int unlockpt(int); 243#endif 244#if __POSIX_VISIBLE >= 200112 245int posix_openpt(int); 246#endif 247 248/* 249 * The Open Group Base Specifications, Issue 7; IEEE Std 1003.1-2008 (POSIX) 250 */ 251#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 252char *mkdtemp(char *); 253#endif 254 255#if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809 256int getsubopt(char **, char * const *, char **); 257#endif 258 259/* 260 * The Open Group Base Specifications, post-Issue 7 261 */ 262#if __BSD_VISIBLE 263int mkostemp(char *, int); 264#endif 265 266#if __BSD_VISIBLE 267#define alloca(n) __builtin_alloca(n) 268 269char *getbsize(int *, long *); 270char *cgetcap(char *, const char *, int); 271int cgetclose(void); 272int cgetent(char **, char **, const char *); 273int cgetfirst(char **, char **); 274int cgetmatch(char *, const char *); 275int cgetnext(char **, char **); 276int cgetnum(char *, const char *, long *); 277int cgetset(const char *); 278int cgetusedb(int); 279int cgetstr(char *, const char *, char **); 280int cgetustr(char *, const char *, char **); 281 282int daemon(int, int); 283char *devname(dev_t, mode_t); 284int getloadavg(double [], int); 285 286const char * 287 getprogname(void); 288void setprogname(const char *); 289 290extern char *suboptarg; /* getsubopt(3) external variable */ 291 292char * mkdtemps(char *, int); 293int mkstemps(char *, int); 294int mkostemps(char *, int, int); 295 296int heapsort(void *, size_t, size_t, int (*)(const void *, const void *)); 297int mergesort(void *, size_t, size_t, int (*)(const void *, const void *)); 298int radixsort(const unsigned char **, int, const unsigned char *, 299 unsigned); 300int sradixsort(const unsigned char **, int, const unsigned char *, 301 unsigned); 302 303void srandomdev(void); 304long long 305 strtonum(const char *, long long, long long, const char **); 306 307void setproctitle(const char *, ...) 308 __attribute__((__format__ (__printf__, 1, 2))); 309 310quad_t qabs(quad_t); 311qdiv_t qdiv(quad_t, quad_t); 312quad_t strtoq(const char *__restrict, char **__restrict, int); 313u_quad_t strtouq(const char *__restrict, char **__restrict, int); 314 315uint32_t arc4random(void); 316uint32_t arc4random_uniform(uint32_t); 317void arc4random_buf(void *, size_t) 318 __attribute__((__bounded__ (__buffer__,1,2))); 319 320#endif /* __BSD_VISIBLE */ 321 322__END_DECLS 323 324#endif /* _STDLIB_H_ */ 325