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