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