Home | History | Annotate | Line # | Download | only in libkern
libkern.h revision 1.32.2.7
      1  1.32.2.6   nathanw /*	$NetBSD: libkern.h,v 1.32.2.7 2002/10/18 02:44:59 nathanw Exp $	*/
      2       1.3       cgd 
      3       1.1       cgd /*-
      4       1.1       cgd  * Copyright (c) 1992, 1993
      5       1.1       cgd  *	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.1       cgd  * 3. All advertising materials mentioning features or use of this software
     16       1.1       cgd  *    must display the following acknowledgement:
     17       1.1       cgd  *	This product includes software developed by the University of
     18       1.1       cgd  *	California, Berkeley and its contributors.
     19       1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     20       1.1       cgd  *    may be used to endorse or promote products derived from this software
     21       1.1       cgd  *    without specific prior written permission.
     22       1.1       cgd  *
     23       1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24       1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25       1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26       1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27       1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28       1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29       1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30       1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31       1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32       1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33       1.1       cgd  * SUCH DAMAGE.
     34       1.1       cgd  *
     35      1.21      fvdl  *	@(#)libkern.h	8.2 (Berkeley) 8/5/94
     36       1.1       cgd  */
     37       1.1       cgd 
     38      1.29    simonb #ifndef _LIB_LIBKERN_LIBKERN_H_
     39      1.29    simonb #define _LIB_LIBKERN_LIBKERN_H_
     40      1.29    simonb 
     41       1.1       cgd #include <sys/types.h>
     42       1.4       cgd 
     43       1.7  christos #ifndef LIBKERN_INLINE
     44       1.7  christos #define LIBKERN_INLINE	static __inline
     45       1.7  christos #define LIBKERN_BODY
     46       1.7  christos #endif
     47       1.7  christos 
     48      1.14       cgd LIBKERN_INLINE int imax __P((int, int)) __attribute__ ((unused));
     49      1.14       cgd LIBKERN_INLINE int imin __P((int, int)) __attribute__ ((unused));
     50      1.14       cgd LIBKERN_INLINE u_int max __P((u_int, u_int)) __attribute__ ((unused));
     51      1.14       cgd LIBKERN_INLINE u_int min __P((u_int, u_int)) __attribute__ ((unused));
     52      1.14       cgd LIBKERN_INLINE long lmax __P((long, long)) __attribute__ ((unused));
     53      1.14       cgd LIBKERN_INLINE long lmin __P((long, long)) __attribute__ ((unused));
     54      1.14       cgd LIBKERN_INLINE u_long ulmax __P((u_long, u_long)) __attribute__ ((unused));
     55      1.14       cgd LIBKERN_INLINE u_long ulmin __P((u_long, u_long)) __attribute__ ((unused));
     56      1.14       cgd LIBKERN_INLINE int abs __P((int)) __attribute__ ((unused));
     57       1.1       cgd 
     58  1.32.2.1   nathanw LIBKERN_INLINE int isspace __P((int)) __attribute__((__unused__));
     59  1.32.2.1   nathanw LIBKERN_INLINE int isascii __P((int)) __attribute__((__unused__));
     60  1.32.2.1   nathanw LIBKERN_INLINE int isupper __P((int)) __attribute__((__unused__));
     61  1.32.2.1   nathanw LIBKERN_INLINE int islower __P((int)) __attribute__((__unused__));
     62  1.32.2.1   nathanw LIBKERN_INLINE int isalpha __P((int)) __attribute__((__unused__));
     63  1.32.2.1   nathanw LIBKERN_INLINE int isdigit __P((int)) __attribute__((__unused__));
     64  1.32.2.1   nathanw LIBKERN_INLINE int isxdigit __P((int)) __attribute__((__unused__));
     65  1.32.2.1   nathanw LIBKERN_INLINE int toupper __P((int)) __attribute__((__unused__));
     66  1.32.2.1   nathanw LIBKERN_INLINE int tolower __P((int)) __attribute__((__unused__));
     67  1.32.2.1   nathanw 
     68       1.7  christos #ifdef LIBKERN_BODY
     69       1.7  christos LIBKERN_INLINE int
     70  1.32.2.7   nathanw imax(int a, int b)
     71       1.1       cgd {
     72       1.1       cgd 	return (a > b ? a : b);
     73       1.1       cgd }
     74       1.7  christos LIBKERN_INLINE int
     75  1.32.2.7   nathanw imin(int a, int b)
     76       1.1       cgd {
     77       1.1       cgd 	return (a < b ? a : b);
     78       1.1       cgd }
     79       1.7  christos LIBKERN_INLINE long
     80  1.32.2.7   nathanw lmax(long a, long b)
     81       1.1       cgd {
     82       1.1       cgd 	return (a > b ? a : b);
     83       1.1       cgd }
     84       1.7  christos LIBKERN_INLINE long
     85  1.32.2.7   nathanw lmin(long a, long b)
     86       1.1       cgd {
     87       1.1       cgd 	return (a < b ? a : b);
     88       1.1       cgd }
     89       1.7  christos LIBKERN_INLINE u_int
     90  1.32.2.7   nathanw max(u_int a, u_int b)
     91       1.1       cgd {
     92       1.1       cgd 	return (a > b ? a : b);
     93       1.1       cgd }
     94       1.7  christos LIBKERN_INLINE u_int
     95  1.32.2.7   nathanw min(u_int a, u_int b)
     96       1.1       cgd {
     97       1.1       cgd 	return (a < b ? a : b);
     98       1.1       cgd }
     99       1.7  christos LIBKERN_INLINE u_long
    100  1.32.2.7   nathanw ulmax(u_long a, u_long b)
    101       1.1       cgd {
    102       1.1       cgd 	return (a > b ? a : b);
    103       1.1       cgd }
    104       1.7  christos LIBKERN_INLINE u_long
    105  1.32.2.7   nathanw ulmin(u_long a, u_long b)
    106       1.1       cgd {
    107       1.1       cgd 	return (a < b ? a : b);
    108       1.5       leo }
    109       1.5       leo 
    110       1.7  christos LIBKERN_INLINE int
    111  1.32.2.7   nathanw abs(int j)
    112       1.5       leo {
    113       1.5       leo 	return(j < 0 ? -j : j);
    114  1.32.2.1   nathanw }
    115  1.32.2.1   nathanw 
    116  1.32.2.1   nathanw LIBKERN_INLINE int
    117  1.32.2.7   nathanw isspace(int ch)
    118  1.32.2.1   nathanw {
    119  1.32.2.1   nathanw 	return (ch == ' ' || (ch >= '\t' && ch <= '\r'));
    120  1.32.2.1   nathanw }
    121  1.32.2.1   nathanw 
    122  1.32.2.1   nathanw LIBKERN_INLINE int
    123  1.32.2.7   nathanw isascii(int ch)
    124  1.32.2.1   nathanw {
    125  1.32.2.1   nathanw 	return ((ch & ~0x7f) == 0);
    126  1.32.2.1   nathanw }
    127  1.32.2.1   nathanw 
    128  1.32.2.1   nathanw LIBKERN_INLINE int
    129  1.32.2.7   nathanw isupper(int ch)
    130  1.32.2.1   nathanw {
    131  1.32.2.1   nathanw 	return (ch >= 'A' && ch <= 'Z');
    132  1.32.2.1   nathanw }
    133  1.32.2.1   nathanw 
    134  1.32.2.1   nathanw LIBKERN_INLINE int
    135  1.32.2.7   nathanw islower(int ch)
    136  1.32.2.1   nathanw {
    137  1.32.2.1   nathanw 	return (ch >= 'a' && ch <= 'z');
    138  1.32.2.1   nathanw }
    139  1.32.2.1   nathanw 
    140  1.32.2.1   nathanw LIBKERN_INLINE int
    141  1.32.2.7   nathanw isalpha(int ch)
    142  1.32.2.1   nathanw {
    143  1.32.2.1   nathanw 	return (isupper(ch) || islower(ch));
    144  1.32.2.1   nathanw }
    145  1.32.2.1   nathanw 
    146  1.32.2.1   nathanw LIBKERN_INLINE int
    147  1.32.2.7   nathanw isdigit(int ch)
    148  1.32.2.1   nathanw {
    149  1.32.2.1   nathanw 	return (ch >= '0' && ch <= '9');
    150  1.32.2.1   nathanw }
    151  1.32.2.1   nathanw 
    152  1.32.2.1   nathanw LIBKERN_INLINE int
    153  1.32.2.7   nathanw isxdigit(int ch)
    154  1.32.2.1   nathanw {
    155  1.32.2.1   nathanw 	return (isdigit(ch) ||
    156  1.32.2.1   nathanw 	    (ch >= 'A' && ch <= 'F') ||
    157  1.32.2.1   nathanw 	    (ch >= 'a' && ch <= 'f'));
    158  1.32.2.1   nathanw }
    159  1.32.2.1   nathanw 
    160  1.32.2.1   nathanw LIBKERN_INLINE int
    161  1.32.2.7   nathanw toupper(int ch)
    162  1.32.2.1   nathanw {
    163  1.32.2.1   nathanw 	if (islower(ch))
    164  1.32.2.1   nathanw 		return (ch - 0x20);
    165  1.32.2.1   nathanw 	return (ch);
    166  1.32.2.1   nathanw }
    167  1.32.2.1   nathanw 
    168  1.32.2.1   nathanw LIBKERN_INLINE int
    169  1.32.2.7   nathanw tolower(int ch)
    170  1.32.2.1   nathanw {
    171  1.32.2.1   nathanw 	if (isupper(ch))
    172  1.32.2.1   nathanw 		return (ch + 0x20);
    173  1.32.2.1   nathanw 	return (ch);
    174       1.1       cgd }
    175       1.7  christos #endif
    176       1.1       cgd 
    177       1.9       cgd #ifdef NDEBUG						/* tradition! */
    178       1.9       cgd #define	assert(e)	((void)0)
    179      1.10       cgd #else
    180       1.9       cgd #ifdef __STDC__
    181      1.30   thorpej #define	assert(e)	(__predict_true((e)) ? (void)0 :		    \
    182       1.9       cgd 			    __assert("", __FILE__, __LINE__, #e))
    183       1.9       cgd #else
    184      1.30   thorpej #define	assert(e)	(__predict_true((e)) ? (void)0 :		    \
    185       1.9       cgd 			    __assert("", __FILE__, __LINE__, "e"))
    186       1.9       cgd #endif
    187       1.9       cgd #endif
    188       1.9       cgd 
    189       1.9       cgd #ifndef DIAGNOSTIC
    190  1.32.2.2   nathanw #ifdef lint
    191  1.32.2.2   nathanw #define	KASSERT(e)	/* NOTHING */
    192  1.32.2.2   nathanw #else /* !lint */
    193       1.9       cgd #define	KASSERT(e)	((void)0)
    194  1.32.2.2   nathanw #endif /* !lint */
    195       1.9       cgd #else
    196       1.9       cgd #ifdef __STDC__
    197      1.30   thorpej #define	KASSERT(e)	(__predict_true((e)) ? (void)0 :		    \
    198       1.9       cgd 			    __assert("diagnostic ", __FILE__, __LINE__, #e))
    199       1.9       cgd #else
    200      1.30   thorpej #define	KASSERT(e)	(__predict_true((e)) ? (void)0 :		    \
    201       1.9       cgd 			    __assert("diagnostic ", __FILE__, __LINE__, "e"))
    202       1.9       cgd #endif
    203       1.9       cgd #endif
    204       1.9       cgd 
    205       1.9       cgd #ifndef DEBUG
    206  1.32.2.2   nathanw #ifdef lint
    207  1.32.2.2   nathanw #define	KDASSERT(e)	/* NOTHING */
    208  1.32.2.2   nathanw #else /* lint */
    209       1.9       cgd #define	KDASSERT(e)	((void)0)
    210  1.32.2.2   nathanw #endif /* lint */
    211       1.9       cgd #else
    212       1.9       cgd #ifdef __STDC__
    213      1.30   thorpej #define	KDASSERT(e)	(__predict_true((e)) ? (void)0 :		    \
    214       1.9       cgd 			    __assert("debugging ", __FILE__, __LINE__, #e))
    215       1.9       cgd #else
    216      1.30   thorpej #define	KDASSERT(e)	(__predict_true((e)) ? (void)0 :		    \
    217       1.9       cgd 			    __assert("debugging ", __FILE__, __LINE__, "e"))
    218       1.9       cgd #endif
    219       1.9       cgd #endif
    220      1.19   thorpej 
    221      1.31   msaitoh #ifndef offsetof
    222      1.19   thorpej #define	offsetof(type, member)	((size_t)(&((type *)0)->member))
    223      1.31   msaitoh #endif
    224       1.9       cgd 
    225       1.1       cgd /* Prototypes for non-quad routines. */
    226  1.32.2.3   nathanw /* XXX notyet #ifdef _STANDALONE */
    227       1.1       cgd int	 bcmp __P((const void *, const void *, size_t));
    228      1.13  drochner void	 bzero __P((void *, size_t));
    229  1.32.2.3   nathanw /* #endif */
    230  1.32.2.4   nathanw 
    231  1.32.2.4   nathanw /* Prototypes for which GCC built-ins exist. */
    232  1.32.2.4   nathanw void	*memcpy __P((void *, const void *, size_t));
    233  1.32.2.4   nathanw int	 memcmp __P((const void *, const void *, size_t));
    234  1.32.2.4   nathanw void	*memset __P((void *, int, size_t));
    235  1.32.2.4   nathanw #if __GNUC_PREREQ__(2, 95)
    236  1.32.2.4   nathanw #define	memcpy(d, s, l)		__builtin_memcpy(d, s, l)
    237  1.32.2.4   nathanw #define	memcmp(a, b, l)		__builtin_memcmp(a, b, l)
    238  1.32.2.4   nathanw #define	memset(d, v, l)		__builtin_memset(d, v, l)
    239  1.32.2.4   nathanw #endif
    240  1.32.2.4   nathanw 
    241  1.32.2.4   nathanw char	*strcpy __P((char *, const char *));
    242  1.32.2.4   nathanw int	 strcmp __P((const char *, const char *));
    243  1.32.2.4   nathanw size_t	 strlen __P((const char *));
    244  1.32.2.4   nathanw #if __GNUC_PREREQ__(2, 95)
    245  1.32.2.4   nathanw #define	strcpy(d, s)		__builtin_strcpy(d, s)
    246  1.32.2.4   nathanw #define	strcmp(a, b)		__builtin_strcmp(a, b)
    247  1.32.2.4   nathanw #define	strlen(a)		__builtin_strlen(a)
    248  1.32.2.4   nathanw #endif
    249  1.32.2.4   nathanw 
    250  1.32.2.4   nathanw /* Functions for which we always use built-ins. */
    251  1.32.2.4   nathanw #ifdef __GNUC__
    252  1.32.2.4   nathanw #define	alloca(s)		__builtin_alloca(s)
    253  1.32.2.4   nathanw #endif
    254  1.32.2.4   nathanw 
    255  1.32.2.4   nathanw /* These exist in GCC 3.x, but we don't bother. */
    256  1.32.2.4   nathanw char	*strcat __P((char *, const char *));
    257  1.32.2.4   nathanw char	*strncpy __P((char *, const char *, size_t));
    258  1.32.2.4   nathanw int	 strncmp __P((const char *, const char *, size_t));
    259  1.32.2.4   nathanw char	*strchr __P((const char *, int));
    260  1.32.2.4   nathanw char	*strrchr __P((const char *, int));
    261  1.32.2.4   nathanw 
    262  1.32.2.7   nathanw char	*strstr __P((const char *, const char *));
    263  1.32.2.7   nathanw 
    264  1.32.2.6   nathanw /*
    265  1.32.2.6   nathanw  * ffs is an instruction on vax.
    266  1.32.2.6   nathanw  */
    267  1.32.2.4   nathanw int	 ffs __P((int));
    268  1.32.2.6   nathanw #if __GNUC_PREREQ__(2, 95) && !defined(__vax__)
    269  1.32.2.6   nathanw #define	ffs(x)			__builtin_ffs(x)
    270  1.32.2.6   nathanw #endif
    271  1.32.2.4   nathanw 
    272  1.32.2.3   nathanw void	 __assert __P((const char *, const char *, int, const char *))
    273  1.32.2.3   nathanw 	    __attribute__((__noreturn__));
    274      1.28    simonb u_int32_t
    275      1.28    simonb 	 inet_addr __P((const char *));
    276      1.28    simonb char	*intoa __P((u_int32_t));
    277      1.28    simonb #define inet_ntoa(a) intoa((a).s_addr)
    278      1.15    mjacob void	*memchr __P((const void *, int, size_t));
    279      1.23     perry void	*memmove __P((void *, const void *, size_t));
    280      1.22  christos int	 pmatch __P((const char *, const char *, const char **));
    281  1.32.2.5   nathanw u_int32_t arc4random __P((void));
    282  1.32.2.7   nathanw void	 arc4randbytes __P((void *, size_t));
    283       1.1       cgd u_long	 random __P((void));
    284      1.11       cgd int	 scanc __P((u_int, const u_char *, const u_char *, int));
    285       1.7  christos int	 skpc __P((int, size_t, u_char *));
    286      1.32   thorpej int	 strcasecmp __P((const char *, const char *));
    287      1.28    simonb int	 strncasecmp __P((const char *, const char *, size_t));
    288      1.28    simonb u_long	 strtoul __P((const char *, char **, int));
    289      1.29    simonb #endif /* !_LIB_LIBKERN_LIBKERN_H_ */
    290