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