stdlib.h revision 1.118
1/* $NetBSD: stdlib.h,v 1.118 2017/10/07 19:38:09 christos Exp $ */ 2 3/*- 4 * Copyright (c) 1990, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of the University nor the names of its contributors 16 * may be used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 * 31 * @(#)stdlib.h 8.5 (Berkeley) 5/19/95 32 */ 33 34#ifndef _STDLIB_H_ 35#define _STDLIB_H_ 36 37#include <sys/cdefs.h> 38#include <sys/featuretest.h> 39 40#if defined(_NETBSD_SOURCE) 41#include <sys/types.h> /* for quad_t, etc. */ 42#endif 43 44#include <machine/ansi.h> 45 46#ifdef _BSD_SIZE_T_ 47typedef _BSD_SIZE_T_ size_t; 48#undef _BSD_SIZE_T_ 49#endif 50 51#if defined(_BSD_WCHAR_T_) && !defined(__cplusplus) 52typedef _BSD_WCHAR_T_ wchar_t; 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) && \ 67 (defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \ 68 (__cplusplus - 0) >= 201103L || defined(_NETBSD_SOURCE)) 69typedef struct { 70 /* LONGLONG */ 71 long long int quot; /* quotient */ 72 /* LONGLONG */ 73 long long int rem; /* remainder */ 74} lldiv_t; 75#endif 76 77#if defined(_NETBSD_SOURCE) 78typedef struct { 79 quad_t quot; /* quotient */ 80 quad_t rem; /* remainder */ 81} qdiv_t; 82#endif 83 84 85#include <sys/null.h> 86 87#define EXIT_FAILURE 1 88#define EXIT_SUCCESS 0 89 90#define RAND_MAX 0x7fffffff 91 92extern size_t __mb_cur_max; 93#define MB_CUR_MAX __mb_cur_max 94 95__BEGIN_DECLS 96__dead void _Exit(int); 97__dead void abort(void); 98__pure int abs(int); 99int atexit(void (*)(void)); 100double atof(const char *); 101int atoi(const char *); 102long atol(const char *); 103#ifndef __BSEARCH_DECLARED 104#define __BSEARCH_DECLARED 105/* also in search.h */ 106void *bsearch(const void *, const void *, size_t, size_t, 107 int (*)(const void *, const void *)); 108#endif /* __BSEARCH_DECLARED */ 109void *calloc(size_t, size_t); 110div_t div(int, int); 111__dead void exit(int); 112void free(void *); 113__aconst char *getenv(const char *); 114__pure long 115 labs(long); 116ldiv_t ldiv(long, long); 117void *malloc(size_t); 118void qsort(void *, size_t, size_t, int (*)(const void *, const void *)); 119int rand(void); 120void *realloc(void *, size_t); 121void srand(unsigned); 122double strtod(const char * __restrict, char ** __restrict); 123long strtol(const char * __restrict, char ** __restrict, int); 124unsigned long 125 strtoul(const char * __restrict, char ** __restrict, int); 126#ifdef _OPENBSD_SOURCE 127long long strtonum(const char *, long long, long long, const char **); 128void *reallocarray(void *, size_t, size_t); 129void *recallocarray(void *, size_t, size_t, size_t); 130#endif 131int system(const char *); 132 133/* These are currently just stubs. */ 134int mblen(const char *, size_t); 135size_t mbstowcs(wchar_t * __restrict, const char * __restrict, size_t); 136int wctomb(char *, wchar_t); 137int mbtowc(wchar_t * __restrict, const char * __restrict, size_t); 138size_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t); 139 140#if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \ 141 defined(_NETBSD_SOURCE) 142 143 144/* 145 * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2 146 */ 147#if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \ 148 defined(_REENTRANT) || defined(_NETBSD_SOURCE) 149int rand_r(unsigned int *); 150#endif 151 152 153/* 154 * X/Open Portability Guide >= Issue 4 155 */ 156#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) 157double drand48(void); 158double erand48(unsigned short[3]); 159long jrand48(unsigned short[3]); 160void lcong48(unsigned short[7]); 161long lrand48(void); 162long mrand48(void); 163long nrand48(unsigned short[3]); 164unsigned short * 165 seed48(unsigned short[3]); 166void srand48(long); 167 168#ifndef __LIBC12_SOURCE__ 169int putenv(char *) __RENAME(__putenv50); 170#endif 171#endif 172 173 174/* 175 * X/Open Portability Guide >= Issue 4 Version 2 176 */ 177#if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \ 178 (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE) 179long a64l(const char *); 180char *l64a(long); 181 182long random(void); 183char *setstate(char *); 184#ifndef __LIBC12_SOURCE__ 185char *initstate(unsigned int, char *, size_t) __RENAME(__initstate60); 186void srandom(unsigned int) __RENAME(__srandom60); 187#endif 188#ifdef _NETBSD_SOURCE 189#define RANDOM_MAX 0x7fffffff /* (((long)1 << 31) - 1) */ 190int mkostemp(char *, int); 191int mkostemps(char *, int, int); 192#endif 193 194char *mkdtemp(char *); 195int mkstemp(char *); 196char *mktemp(char *) 197#ifdef __MKTEMP_OK__ 198 __RENAME(_mktemp) 199#endif 200 ; 201 202int setkey(const char *); 203 204char *realpath(const char * __restrict, char * __restrict); 205 206int ttyslot(void); 207 208void *valloc(size_t); /* obsoleted by malloc() */ 209 210int grantpt(int); 211int unlockpt(int); 212char *ptsname(int); 213#endif 214 215/* 216 * ISO C99 217 */ 218#if defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \ 219 defined(_NETBSD_SOURCE) || (__cplusplus - 0) >= 201103L 220 221/* LONGLONG */ 222long long int atoll(const char *); 223/* LONGLONG */ 224long long int llabs(long long int); 225/* LONGLONG */ 226lldiv_t lldiv(long long int, long long int); 227/* LONGLONG */ 228long long int strtoll(const char * __restrict, char ** __restrict, int); 229/* LONGLONG */ 230unsigned long long int 231 strtoull(const char * __restrict, char ** __restrict, int); 232float strtof(const char * __restrict, char ** __restrict); 233long double strtold(const char * __restrict, char ** __restrict); 234#endif 235 236#if defined(_ISOC11_SOURCE) || (__STDC_VERSION__ - 0) >= 201101L || \ 237 defined(_NETBSD_SOURCE) || (__cplusplus - 0) >= 201103L 238void *aligned_alloc(size_t, size_t); 239int at_quick_exit(void (*)(void)); 240__dead void quick_exit(int); 241#endif 242 243/* 244 * The Open Group Base Specifications, Issue 6; IEEE Std 1003.1-2001 (POSIX) 245 */ 246#if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 600 || \ 247 defined(_NETBSD_SOURCE) 248int setenv(const char *, const char *, int); 249#ifndef __LIBC12_SOURCE__ 250int unsetenv(const char *) __RENAME(__unsetenv13); 251#endif 252 253int posix_openpt(int); 254int posix_memalign(void **, size_t, size_t); 255#endif 256 257/* 258 * Implementation-defined extensions 259 */ 260#if defined(_NETBSD_SOURCE) 261#if defined(alloca) && (alloca == __builtin_alloca) && \ 262 defined(__GNUC__) && (__GNUC__ < 2) 263void *alloca(int); /* built-in for gcc */ 264#elif defined(__PCC__) && !defined(__GNUC__) 265#define alloca(size) __builtin_alloca(size) 266#else 267void *alloca(size_t); 268#endif /* __GNUC__ */ 269 270uint32_t arc4random(void); 271void arc4random_stir(void); 272void arc4random_buf(void *, size_t); 273uint32_t arc4random_uniform(uint32_t); 274void arc4random_addrandom(u_char *, int); 275char *getbsize(int *, long *); 276char *cgetcap(char *, const char *, int); 277int cgetclose(void); 278int cgetent(char **, const char * const *, const char *); 279int cgetfirst(char **, const char * const *); 280int cgetmatch(const char *, const char *); 281int cgetnext(char **, const char * const *); 282int cgetnum(char *, const char *, long *); 283int cgetset(const char *); 284int cgetstr(char *, const char *, char **); 285int cgetustr(char *, const char *, char **); 286void csetexpandtc(int); 287 288int daemon(int, int); 289int devname_r(dev_t, mode_t, char *, size_t); 290#ifndef __LIBC12_SOURCE__ 291__aconst char *devname(dev_t, mode_t) __RENAME(__devname50); 292#endif 293 294#define HN_DECIMAL 0x01 295#define HN_NOSPACE 0x02 296#define HN_B 0x04 297#define HN_DIVISOR_1000 0x08 298 299#define HN_GETSCALE 0x10 300#define HN_AUTOSCALE 0x20 301 302int humanize_number(char *, size_t, int64_t, const char *, int, int); 303int dehumanize_number(const char *, int64_t *); 304ssize_t hmac(const char *, const void *, size_t, const void *, size_t, void *, 305 size_t); 306 307devmajor_t getdevmajor(const char *, mode_t); 308int getloadavg(double [], int); 309 310int getenv_r(const char *, char *, size_t); 311 312void cfree(void *); 313 314int heapsort(void *, size_t, size_t, int (*)(const void *, const void *)); 315int mergesort(void *, size_t, size_t, 316 int (*)(const void *, const void *)); 317int ptsname_r(int, char *, size_t); 318int radixsort(const unsigned char **, int, const unsigned char *, 319 unsigned); 320int sradixsort(const unsigned char **, int, const unsigned char *, 321 unsigned); 322 323void mi_vector_hash(const void * __restrict, size_t, uint32_t, 324 uint32_t[3]); 325 326void setproctitle(const char *, ...) 327 __printflike(1, 2); 328const char *getprogname(void) __constfunc; 329void setprogname(const char *); 330 331quad_t qabs(quad_t); 332quad_t strtoq(const char * __restrict, char ** __restrict, int); 333u_quad_t strtouq(const char * __restrict, char ** __restrict, int); 334 335 /* LONGLONG */ 336long long strsuftoll(const char *, const char *, long long, long long); 337 /* LONGLONG */ 338long long strsuftollx(const char *, const char *, long long, long long, 339 char *, size_t); 340 341int l64a_r(long, char *, int); 342 343size_t shquote(const char *, char *, size_t); 344size_t shquotev(int, char * const *, char *, size_t); 345 346int reallocarr(void *, size_t, size_t); 347#endif /* _NETBSD_SOURCE */ 348#endif /* _POSIX_C_SOURCE || _XOPEN_SOURCE || _NETBSD_SOURCE */ 349 350#if defined(_NETBSD_SOURCE) 351qdiv_t qdiv(quad_t, quad_t); 352#endif 353 354#if (_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE) 355# ifndef __LOCALE_T_DECLARED 356typedef struct _locale *locale_t; 357# define __LOCALE_T_DECLARED 358# endif 359double strtod_l(const char * __restrict, char ** __restrict, locale_t); 360float strtof_l(const char * __restrict, char ** __restrict, locale_t); 361long double strtold_l(const char * __restrict, char ** __restrict, 362 locale_t); 363long strtol_l(const char * __restrict, char ** __restrict, int, locale_t); 364unsigned long 365 strtoul_l(const char * __restrict, char ** __restrict, int, locale_t); 366/* LONGLONG */ 367long long int 368 strtoll_l(const char * __restrict, char ** __restrict, int, locale_t); 369/* LONGLONG */ 370unsigned long long int 371 strtoull_l(const char * __restrict, char ** __restrict, int, locale_t); 372 373# if defined(_NETBSD_SOURCE) 374quad_t strtoq_l(const char * __restrict, char ** __restrict, int, locale_t); 375u_quad_t strtouq_l(const char * __restrict, char ** __restrict, int, locale_t); 376 377size_t _mb_cur_max_l(locale_t); 378#define MB_CUR_MAX_L(loc) _mb_cur_max_l(loc) 379int mblen_l(const char *, size_t, locale_t); 380size_t mbstowcs_l(wchar_t * __restrict, const char * __restrict, size_t, 381 locale_t); 382int wctomb_l(char *, wchar_t, locale_t); 383int mbtowc_l(wchar_t * __restrict, const char * __restrict, size_t, 384 locale_t); 385size_t wcstombs_l(char * __restrict, const wchar_t * __restrict, size_t, 386 locale_t); 387 388# endif /* _NETBSD_SOURCE */ 389#endif /* _POSIX_C_SOURCE >= 200809 || _NETBSD_SOURCE */ 390 391__END_DECLS 392 393#endif /* !_STDLIB_H_ */ 394