stdlib.h revision 103012
11539Srgrimes/*- 21539Srgrimes * Copyright (c) 1990, 1993 31539Srgrimes * The Regents of the University of California. All rights reserved. 41539Srgrimes * 51539Srgrimes * Redistribution and use in source and binary forms, with or without 61539Srgrimes * modification, are permitted provided that the following conditions 71539Srgrimes * are met: 81539Srgrimes * 1. Redistributions of source code must retain the above copyright 91539Srgrimes * notice, this list of conditions and the following disclaimer. 101539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111539Srgrimes * notice, this list of conditions and the following disclaimer in the 121539Srgrimes * documentation and/or other materials provided with the distribution. 131539Srgrimes * 3. All advertising materials mentioning features or use of this software 141539Srgrimes * must display the following acknowledgement: 151539Srgrimes * This product includes software developed by the University of 161539Srgrimes * California, Berkeley and its contributors. 171539Srgrimes * 4. Neither the name of the University nor the names of its contributors 181539Srgrimes * may be used to endorse or promote products derived from this software 191539Srgrimes * without specific prior written permission. 201539Srgrimes * 211539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241539Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311539Srgrimes * SUCH DAMAGE. 321539Srgrimes * 3323657Speter * @(#)stdlib.h 8.5 (Berkeley) 5/19/95 3455031Sbde * $FreeBSD: head/include/stdlib.h 103012 2002-09-06 11:24:06Z tjr $ 351539Srgrimes */ 361539Srgrimes 371539Srgrimes#ifndef _STDLIB_H_ 387865Sbde#define _STDLIB_H_ 391539Srgrimes 4033861Sbde#include <sys/cdefs.h> 41102227Smike#include <sys/_types.h> 4233861Sbde 4326636Sache#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 44102227Smike#ifndef _RUNE_T_DECLARED 45102227Smiketypedef __rune_t rune_t; 46102227Smike#define _RUNE_T_DECLARED 4715483Sbde#endif 4815483Sbde#endif 4915483Sbde 50102227Smike#ifndef _SIZE_T_DECLARED 51102227Smiketypedef __size_t size_t; 52102227Smike#define _SIZE_T_DECLARED 531539Srgrimes#endif 541539Srgrimes 5599640Sobrien#ifndef __cplusplus 56102227Smike#ifndef _WCHAR_T_DECLARED 57102227Smiketypedef __wchar_t wchar_t; 58102227Smike#define _WCHAR_T_DECLARED 591539Srgrimes#endif 6099640Sobrien#endif 611539Srgrimes 621539Srgrimestypedef struct { 631539Srgrimes int quot; /* quotient */ 641539Srgrimes int rem; /* remainder */ 651539Srgrimes} div_t; 661539Srgrimes 671539Srgrimestypedef struct { 681539Srgrimes long quot; /* quotient */ 691539Srgrimes long rem; /* remainder */ 701539Srgrimes} ldiv_t; 711539Srgrimes 7287071Sbde#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 7386368Smike#ifdef __LONG_LONG_SUPPORTED 7499404Smarkm/* LONGLONG */ 7586368Smiketypedef struct { 7686368Smike long long quot; 7786368Smike long long rem; 7886368Smike} lldiv_t; 7986368Smike#endif 8087071Sbde#endif 8186368Smike 821539Srgrimes#ifndef NULL 831539Srgrimes#define NULL 0 841539Srgrimes#endif 851539Srgrimes 861539Srgrimes#define EXIT_FAILURE 1 871539Srgrimes#define EXIT_SUCCESS 0 881539Srgrimes 891539Srgrimes#define RAND_MAX 0x7fffffff 901539Srgrimes 911539Srgrimesextern int __mb_cur_max; 921539Srgrimes#define MB_CUR_MAX __mb_cur_max 931539Srgrimes 941539Srgrimes__BEGIN_DECLS 9593032Simpvoid abort(void) __dead2; 9693032Simpint abs(int) __pure2; 9793032Simpint atexit(void (*)(void)); 9893032Simpdouble atof(const char *); 9993032Simpint atoi(const char *); 10093032Simplong atol(const char *); 10193032Simpvoid *bsearch(const void *, const void *, size_t, 10293032Simp size_t, int (*)(const void *, const void *)); 10393032Simpvoid *calloc(size_t, size_t); 10493032Simpdiv_t div(int, int) __pure2; 10593032Simpvoid exit(int) __dead2; 10693032Simpvoid free(void *); 10793032Simpchar *getenv(const char *); 10893032Simplong labs(long) __pure2; 10993032Simpldiv_t ldiv(long, long) __pure2; 11093032Simpvoid *malloc(size_t); 11193032Simpvoid qsort(void *, size_t, size_t, 11293032Simp int (*)(const void *, const void *)); 11393032Simpint rand(void); 11493032Simpvoid *realloc(void *, size_t); 11593032Simpvoid srand(unsigned); 116103012Stjrdouble strtod(const char * __restrict, char ** __restrict); 117103012Stjrlong strtol(const char * __restrict, char ** __restrict, int); 1181539Srgrimesunsigned long 119103012Stjr strtoul(const char * __restrict, char ** __restrict, int); 12093032Simpint system(const char *); 1211539Srgrimes 12293032Simpint mblen(const char *, size_t); 123103012Stjrsize_t mbstowcs(wchar_t * __restrict , const char * __restrict, size_t); 12493032Simpint wctomb(char *, wchar_t); 125103012Stjrint mbtowc(wchar_t * __restrict, const char * __restrict, size_t); 126103012Stjrsize_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t); 1271539Srgrimes 1287865Sbde#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 12995377Sphkextern const char *_malloc_options; 13097639Sphkextern void (*_malloc_message)(const char *p1, const char *p2, const char *p3, const char *p4); 13169201Sphk 13293032Simpint putenv(const char *); 13393032Simpint setenv(const char *, const char *, int); 1341539Srgrimes 13593032Simpdouble drand48(void); 13693032Simpdouble erand48(unsigned short[3]); 13793032Simplong jrand48(unsigned short[3]); 13893032Simpvoid lcong48(unsigned short[7]); 13993032Simplong lrand48(void); 14093032Simplong mrand48(void); 14193032Simplong nrand48(unsigned short[3]); 1427865Sbdeunsigned short 14393032Simp *seed48(unsigned short[3]); 14493032Simpvoid srand48(long); 1454749Sats 14693032Simpvoid *alloca(size_t); /* built-in for gcc */ 1471539Srgrimes /* getcap(3) functions */ 14841927Sdt__uint32_t 14993032Simp arc4random(void); 15093032Simpvoid arc4random_addrandom(unsigned char *dat, int datlen); 15193032Simpvoid arc4random_stir(void); 15287086Sbde#ifdef __LONG_LONG_SUPPORTED 15399404Smarkm/* LONGLONG */ 15487086Sbdelong long 15593032Simp atoll(const char *); 15687086Sbde#endif 15793032Simpchar *getbsize(int *, long *); 15893032Simpchar *cgetcap(char *, const char *, int); 15993032Simpint cgetclose(void); 16093032Simpint cgetent(char **, char **, const char *); 16193032Simpint cgetfirst(char **, char **); 16293032Simpint cgetmatch(const char *, const char *); 16393032Simpint cgetnext(char **, char **); 16493032Simpint cgetnum(char *, const char *, long *); 16593032Simpint cgetset(const char *); 16693032Simpint cgetstr(char *, const char *, char **); 16793032Simpint cgetustr(char *, const char *, char **); 1681539Srgrimes 16993032Simpint daemon(int, int); 17093032Simpchar *devname(int, int); 17193032Simpint getloadavg(double [], int); 17288399Smike__const char * 17393032Simp getprogname(void); 1741539Srgrimes 17593032Simpint heapsort(void *, size_t, size_t, int (*)(const void *, const void *)); 17693032Simpchar *initstate(unsigned long, char *, long); 17787071Sbde#ifdef __LONG_LONG_SUPPORTED 17899404Smarkm/* LONGLONG */ 17987071Sbdelong long 18093032Simp llabs(long long) __pure2; 18193032Simplldiv_t lldiv(long long, long long) __pure2; 18287071Sbde#endif 18393032Simpint mergesort(void *, size_t, size_t, int (*)(const void *, const void *)); 18493032Simpint radixsort(const unsigned char **, int, const unsigned char *, 18593032Simp unsigned); 18693032Simpint sradixsort(const unsigned char **, int, const unsigned char *, 18793032Simp unsigned); 18893032Simpint rand_r(unsigned *); 18993032Simplong random(void); 19093032Simpvoid *reallocf(void *, size_t); 19193032Simpchar *realpath(const char *, char resolved_path[]); 19293032Simpvoid setprogname(const char *); 19393032Simpchar *setstate(char *); 19493032Simpvoid sranddev(void); 19593032Simpvoid srandom(unsigned long); 19693032Simpvoid srandomdev(void); 19787071Sbde#ifdef __LONG_LONG_SUPPORTED 19899404Smarkm/* LONGLONG */ 19987071Sbdelong long 200103012Stjr strtoll(const char * __restrict, char ** __restrict, int); 20187071Sbde#endif 20293032Simp__int64_t strtoq(const char *, char **, int); 20387071Sbde#ifdef __LONG_LONG_SUPPORTED 20499404Smarkm/* LONGLONG */ 20587071Sbdeunsigned long long 206103012Stjr strtoull(const char * __restrict, char ** __restrict, int); 20787071Sbde#endif 20841927Sdt__uint64_t 20993032Simp strtouq(const char *, char **, int); 21093032Simpvoid unsetenv(const char *); 2117865Sbde#endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */ 2121539Srgrimes__END_DECLS 2131539Srgrimes 2147865Sbde#endif /* !_STDLIB_H_ */ 215