Home | History | Annotate | Line # | Download | only in include
stdlib.h revision 1.64
      1  1.64       agc /*	$NetBSD: stdlib.h,v 1.64 2003/08/07 09:44:11 agc 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.58     bjh21 __dead	 void _Exit __P((int)) __attribute__((__noreturn__));
     97  1.41   mycroft __dead	 void abort __P((void)) __attribute__((__noreturn__));
     98  1.40   mycroft __pure	 int abs __P((int));
     99   1.1       cgd int	 atexit __P((void (*)(void)));
    100   1.1       cgd double	 atof __P((const char *));
    101   1.1       cgd int	 atoi __P((const char *));
    102   1.1       cgd long	 atol __P((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.51  christos void	*bsearch __P((const void *, const void *, size_t, size_t,
    107  1.51  christos     int (*)(const void *, const void *)));
    108  1.51  christos #endif /* __BSEARCH_DECLARED */
    109   1.1       cgd void	*calloc __P((size_t, size_t));
    110   1.1       cgd div_t	 div __P((int, int));
    111  1.41   mycroft __dead	 void exit __P((int)) __attribute__((__noreturn__));
    112   1.1       cgd void	 free __P((void *));
    113  1.35   mycroft __aconst char *getenv __P((const char *));
    114  1.30     perry __pure long
    115  1.30     perry 	 labs __P((long));
    116   1.1       cgd ldiv_t	 ldiv __P((long, long));
    117   1.1       cgd void	*malloc __P((size_t));
    118   1.1       cgd void	 qsort __P((void *, size_t, size_t,
    119   1.1       cgd 	    int (*)(const void *, const void *)));
    120   1.1       cgd int	 rand __P((void));
    121   1.1       cgd void	*realloc __P((void *, size_t));
    122   1.1       cgd void	 srand __P((unsigned));
    123  1.54    kleink double	 strtod __P((const char * __restrict, char ** __restrict));
    124  1.54    kleink long	 strtol __P((const char * __restrict, char ** __restrict, int));
    125   1.1       cgd unsigned long
    126  1.54    kleink 	 strtoul __P((const char * __restrict, char ** __restrict, int));
    127   1.1       cgd int	 system __P((const char *));
    128   1.1       cgd 
    129  1.30     perry /* These are currently just stubs. */
    130   1.1       cgd int	 mblen __P((const char *, size_t));
    131  1.54    kleink size_t	 mbstowcs __P((wchar_t * __restrict, const char * __restrict, size_t));
    132   1.1       cgd int	 wctomb __P((char *, wchar_t));
    133  1.54    kleink int	 mbtowc __P((wchar_t * __restrict, const char * __restrict, size_t));
    134  1.54    kleink size_t	 wcstombs __P((char * __restrict, const wchar_t * __restrict, size_t));
    135   1.5    brezak 
    136  1.62     bjh21 #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
    137  1.62     bjh21     defined(_NETBSD_SOURCE)
    138  1.32    kleink 
    139  1.32    kleink 
    140  1.33    kleink /*
    141  1.33    kleink  * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2
    142  1.33    kleink  */
    143  1.62     bjh21 #if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
    144  1.62     bjh21     defined(_REENTRANT) || defined(_NETBSD_SOURCE)
    145  1.33    kleink int	 rand_r __P((unsigned int *));
    146  1.33    kleink #endif
    147  1.32    kleink 
    148  1.32    kleink 
    149  1.33    kleink /*
    150  1.33    kleink  * X/Open Portability Guide >= Issue 4
    151  1.33    kleink  */
    152  1.62     bjh21 #if (_XOPEN_SOURCE - 0) >= 4 || defined(_NETBSD_SOURCE)
    153  1.32    kleink double	 drand48 __P((void));
    154  1.32    kleink double	 erand48 __P((unsigned short[3]));
    155  1.32    kleink long	 jrand48 __P((unsigned short[3]));
    156  1.32    kleink void	 lcong48 __P((unsigned short[7]));
    157  1.32    kleink long	 lrand48 __P((void));
    158  1.32    kleink long	 mrand48 __P((void));
    159  1.32    kleink long	 nrand48 __P((unsigned short[3]));
    160  1.32    kleink unsigned short *
    161  1.32    kleink 	 seed48 __P((unsigned short[3]));
    162  1.32    kleink void	 srand48 __P((long));
    163  1.32    kleink 
    164  1.33    kleink int	 putenv __P((const char *));
    165  1.33    kleink #endif
    166  1.33    kleink 
    167  1.33    kleink 
    168  1.33    kleink /*
    169  1.33    kleink  * X/Open Portability Guide >= Issue 4 Version 2
    170  1.33    kleink  */
    171  1.62     bjh21 #if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
    172  1.62     bjh21     (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
    173  1.33    kleink long	 a64l __P((const char *));
    174  1.33    kleink char	*l64a __P((long));
    175  1.33    kleink 
    176  1.33    kleink char	*initstate __P((unsigned long, char *, size_t));
    177  1.33    kleink long	 random __P((void));
    178  1.33    kleink char	*setstate __P((char *));
    179  1.33    kleink void	 srandom __P((unsigned long));
    180  1.33    kleink 
    181  1.39   mycroft char	*mkdtemp __P((char *));
    182  1.33    kleink int	 mkstemp __P((char *));
    183  1.36   mycroft #ifndef __AUDIT__
    184  1.33    kleink char	*mktemp __P((char *));
    185  1.36   mycroft #endif
    186  1.33    kleink 
    187  1.33    kleink int	 setkey __P((const char *));
    188  1.33    kleink 
    189  1.33    kleink char	*realpath __P((const char *, char *));
    190  1.33    kleink 
    191  1.33    kleink int	 ttyslot __P((void));
    192  1.33    kleink 
    193  1.33    kleink void	*valloc __P((size_t));		/* obsoleted by malloc() */
    194  1.33    kleink #endif
    195  1.33    kleink 
    196  1.45    kleink /*
    197  1.45    kleink  * ISO C99
    198  1.45    kleink  */
    199  1.62     bjh21 #if defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
    200  1.62     bjh21     defined(_NETBSD_SOURCE)
    201  1.45    kleink /* LONGLONG */
    202  1.45    kleink long long int	atoll __P((const char *));
    203  1.45    kleink /* LONGLONG */
    204  1.45    kleink long long int	llabs __P((long long int));
    205  1.45    kleink /* LONGLONG */
    206  1.45    kleink lldiv_t		lldiv __P((long long int, long long int));
    207  1.45    kleink /* LONGLONG */
    208  1.54    kleink long long int	strtoll __P((const char * __restrict, char ** __restrict, int));
    209  1.45    kleink /* LONGLONG */
    210  1.54    kleink unsigned long long int
    211  1.54    kleink 		strtoull __P((const char * __restrict, char ** __restrict,
    212  1.54    kleink 		    int));
    213  1.45    kleink #endif
    214  1.33    kleink 
    215  1.33    kleink /*
    216  1.61    kleink  * The Open Group Base Specifications, Issue 6; IEEE Std 1003.1-2001 (POSIX)
    217  1.59    kleink  */
    218  1.62     bjh21 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 600 || \
    219  1.62     bjh21     defined(_NETBSD_SOURCE)
    220  1.59    kleink int	 setenv __P((const char *, const char *, int));
    221  1.59    kleink #ifdef __LIBC12_SOURCE__
    222  1.59    kleink void	 unsetenv __P((const char *));
    223  1.59    kleink int	 __unsetenv13 __P((const char *));
    224  1.59    kleink #else
    225  1.59    kleink int	 unsetenv __P((const char *))		__RENAME(__unsetenv13);
    226  1.59    kleink #endif
    227  1.59    kleink #endif
    228  1.59    kleink 
    229  1.59    kleink /*
    230  1.33    kleink  * Implementation-defined extensions
    231  1.33    kleink  */
    232  1.62     bjh21 #if defined(_NETBSD_SOURCE)
    233   1.3    brezak #if defined(alloca) && (alloca == __builtin_alloca) && (__GNUC__ < 2)
    234  1.27     mikel void	*alloca __P((int));     /* built-in for gcc */
    235   1.2       cgd #else
    236  1.27     mikel void	*alloca __P((size_t));
    237   1.2       cgd #endif /* __GNUC__ */
    238  1.11       cgd 
    239  1.56    itojun u_int32_t arc4random __P((void));
    240  1.56    itojun void	 arc4random_stir __P((void));
    241  1.56    itojun void	 arc4random_addrandom __P((u_char *, int));
    242  1.13       cgd char	*getbsize __P((int *, long *));
    243  1.34   mycroft char	*cgetcap __P((char *, const char *, int));
    244  1.11       cgd int	 cgetclose __P((void));
    245  1.34   mycroft int	 cgetent __P((char **, char **, const char *));
    246  1.11       cgd int	 cgetfirst __P((char **, char **));
    247  1.34   mycroft int	 cgetmatch __P((const char *, const char *));
    248  1.11       cgd int	 cgetnext __P((char **, char **));
    249  1.34   mycroft int	 cgetnum __P((char *, const char *, long *));
    250  1.34   mycroft int	 cgetset __P((const char *));
    251  1.34   mycroft int	 cgetstr __P((char *, const char *, char **));
    252  1.34   mycroft int	 cgetustr __P((char *, const char *, char **));
    253  1.18   deraadt 
    254  1.18   deraadt int	 daemon __P((int, int));
    255  1.35   mycroft __aconst char *devname __P((dev_t, mode_t));
    256  1.18   deraadt int	 getloadavg __P((double [], int));
    257   1.8       jtc 
    258   1.7       jtc void	 cfree __P((void *));
    259   1.7       jtc 
    260   1.1       cgd int	 heapsort __P((void *, size_t, size_t,
    261   1.1       cgd 	    int (*)(const void *, const void *)));
    262  1.17   mycroft int	 mergesort __P((void *, size_t, size_t,
    263  1.17   mycroft 	    int (*)(const void *, const void *)));
    264  1.17   mycroft int	 radixsort __P((const unsigned char **, int, const unsigned char *,
    265  1.17   mycroft 	    unsigned));
    266  1.17   mycroft int	 sradixsort __P((const unsigned char **, int, const unsigned char *,
    267  1.17   mycroft 	    unsigned));
    268   1.7       jtc 
    269  1.48  sommerfe void	 setproctitle __P((const char *, ...))
    270  1.48  sommerfe 	    __attribute__((__format__(__printf__, 1, 2)));
    271  1.52       cgd const char *getprogname __P((void)) __attribute__((__const__));
    272  1.52       cgd void	setprogname __P((const char *));
    273  1.19       jtc 
    274  1.24       jtc quad_t	 qabs __P((quad_t));
    275  1.54    kleink quad_t	 strtoq __P((const char * __restrict, char ** __restrict, int));
    276  1.54    kleink u_quad_t strtouq __P((const char * __restrict, char ** __restrict, int));
    277  1.57     lukem 
    278  1.57     lukem 	/* LONGLONG */
    279  1.57     lukem long long strsuftoll(const char *, const char *, long long, long long);
    280  1.57     lukem 	/* LONGLONG */
    281  1.57     lukem long long strsuftollx(const char *, const char *, long long, long long,
    282  1.57     lukem 	    		char *, size_t);
    283  1.42    kleink 
    284  1.42    kleink int	 l64a_r __P((long, char *, int));
    285  1.53       cgd 
    286  1.63  kristerw size_t	shquote __P((const char *, char *, size_t));
    287  1.63  kristerw size_t	shquotev __P((int, char * const *, char *, size_t));
    288  1.62     bjh21 #endif /* _NETBSD_SOURCE */
    289  1.62     bjh21 #endif /* _POSIX_C_SOURCE || _XOPEN_SOURCE || _NETBSD_SOURCE */
    290  1.55    kleink 
    291  1.62     bjh21 #if defined(_NETBSD_SOURCE)
    292  1.55    kleink qdiv_t	 qdiv __P((quad_t, quad_t));
    293  1.55    kleink #endif
    294   1.1       cgd __END_DECLS
    295   1.1       cgd 
    296  1.27     mikel #endif /* !_STDLIB_H_ */
    297