Home | History | Annotate | Line # | Download | only in libkern
libkern.h revision 1.32.2.3
      1 /*	$NetBSD: libkern.h,v 1.32.2.3 2001/08/24 00:11:49 nathanw Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1992, 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  *	@(#)libkern.h	8.2 (Berkeley) 8/5/94
     36  */
     37 
     38 #ifndef _LIB_LIBKERN_LIBKERN_H_
     39 #define _LIB_LIBKERN_LIBKERN_H_
     40 
     41 #include <sys/types.h>
     42 
     43 #ifndef LIBKERN_INLINE
     44 #define LIBKERN_INLINE	static __inline
     45 #define LIBKERN_BODY
     46 #endif
     47 
     48 LIBKERN_INLINE int imax __P((int, int)) __attribute__ ((unused));
     49 LIBKERN_INLINE int imin __P((int, int)) __attribute__ ((unused));
     50 LIBKERN_INLINE u_int max __P((u_int, u_int)) __attribute__ ((unused));
     51 LIBKERN_INLINE u_int min __P((u_int, u_int)) __attribute__ ((unused));
     52 LIBKERN_INLINE long lmax __P((long, long)) __attribute__ ((unused));
     53 LIBKERN_INLINE long lmin __P((long, long)) __attribute__ ((unused));
     54 LIBKERN_INLINE u_long ulmax __P((u_long, u_long)) __attribute__ ((unused));
     55 LIBKERN_INLINE u_long ulmin __P((u_long, u_long)) __attribute__ ((unused));
     56 LIBKERN_INLINE int abs __P((int)) __attribute__ ((unused));
     57 
     58 LIBKERN_INLINE int isspace __P((int)) __attribute__((__unused__));
     59 LIBKERN_INLINE int isascii __P((int)) __attribute__((__unused__));
     60 LIBKERN_INLINE int isupper __P((int)) __attribute__((__unused__));
     61 LIBKERN_INLINE int islower __P((int)) __attribute__((__unused__));
     62 LIBKERN_INLINE int isalpha __P((int)) __attribute__((__unused__));
     63 LIBKERN_INLINE int isdigit __P((int)) __attribute__((__unused__));
     64 LIBKERN_INLINE int isxdigit __P((int)) __attribute__((__unused__));
     65 LIBKERN_INLINE int toupper __P((int)) __attribute__((__unused__));
     66 LIBKERN_INLINE int tolower __P((int)) __attribute__((__unused__));
     67 
     68 #ifdef LIBKERN_BODY
     69 LIBKERN_INLINE int
     70 imax(a, b)
     71 	int a, b;
     72 {
     73 	return (a > b ? a : b);
     74 }
     75 LIBKERN_INLINE int
     76 imin(a, b)
     77 	int a, b;
     78 {
     79 	return (a < b ? a : b);
     80 }
     81 LIBKERN_INLINE long
     82 lmax(a, b)
     83 	long a, b;
     84 {
     85 	return (a > b ? a : b);
     86 }
     87 LIBKERN_INLINE long
     88 lmin(a, b)
     89 	long a, b;
     90 {
     91 	return (a < b ? a : b);
     92 }
     93 LIBKERN_INLINE u_int
     94 max(a, b)
     95 	u_int a, b;
     96 {
     97 	return (a > b ? a : b);
     98 }
     99 LIBKERN_INLINE u_int
    100 min(a, b)
    101 	u_int a, b;
    102 {
    103 	return (a < b ? a : b);
    104 }
    105 LIBKERN_INLINE u_long
    106 ulmax(a, b)
    107 	u_long a, b;
    108 {
    109 	return (a > b ? a : b);
    110 }
    111 LIBKERN_INLINE u_long
    112 ulmin(a, b)
    113 	u_long a, b;
    114 {
    115 	return (a < b ? a : b);
    116 }
    117 
    118 LIBKERN_INLINE int
    119 abs(j)
    120 	int j;
    121 {
    122 	return(j < 0 ? -j : j);
    123 }
    124 
    125 LIBKERN_INLINE int
    126 isspace(ch)
    127 	int ch;
    128 {
    129 
    130 	return (ch == ' ' || (ch >= '\t' && ch <= '\r'));
    131 }
    132 
    133 LIBKERN_INLINE int
    134 isascii(ch)
    135 	int ch;
    136 {
    137 
    138 	return ((ch & ~0x7f) == 0);
    139 }
    140 
    141 LIBKERN_INLINE int
    142 isupper(ch)
    143 	int ch;
    144 {
    145 
    146 	return (ch >= 'A' && ch <= 'Z');
    147 }
    148 
    149 LIBKERN_INLINE int
    150 islower(ch)
    151 	int ch;
    152 {
    153 
    154 	return (ch >= 'a' && ch <= 'z');
    155 }
    156 
    157 LIBKERN_INLINE int
    158 isalpha(ch)
    159 	int ch;
    160 {
    161 
    162 	return (isupper(ch) || islower(ch));
    163 }
    164 
    165 LIBKERN_INLINE int
    166 isdigit(ch)
    167 	int ch;
    168 {
    169 
    170 	return (ch >= '0' && ch <= '9');
    171 }
    172 
    173 LIBKERN_INLINE int
    174 isxdigit(ch)
    175 	int ch;
    176 {
    177 
    178 	return (isdigit(ch) ||
    179 	    (ch >= 'A' && ch <= 'F') ||
    180 	    (ch >= 'a' && ch <= 'f'));
    181 }
    182 
    183 LIBKERN_INLINE int
    184 toupper(ch)
    185 	int ch;
    186 {
    187 
    188 	if (islower(ch))
    189 		return (ch - 0x20);
    190 	return (ch);
    191 }
    192 
    193 LIBKERN_INLINE int
    194 tolower(ch)
    195 	int ch;
    196 {
    197 
    198 	if (isupper(ch))
    199 		return (ch + 0x20);
    200 	return (ch);
    201 }
    202 #endif
    203 
    204 #ifdef NDEBUG						/* tradition! */
    205 #define	assert(e)	((void)0)
    206 #else
    207 #ifdef __STDC__
    208 #define	assert(e)	(__predict_true((e)) ? (void)0 :		    \
    209 			    __assert("", __FILE__, __LINE__, #e))
    210 #else
    211 #define	assert(e)	(__predict_true((e)) ? (void)0 :		    \
    212 			    __assert("", __FILE__, __LINE__, "e"))
    213 #endif
    214 #endif
    215 
    216 #ifndef DIAGNOSTIC
    217 #ifdef lint
    218 #define	KASSERT(e)	/* NOTHING */
    219 #else /* !lint */
    220 #define	KASSERT(e)	((void)0)
    221 #endif /* !lint */
    222 #else
    223 #ifdef __STDC__
    224 #define	KASSERT(e)	(__predict_true((e)) ? (void)0 :		    \
    225 			    __assert("diagnostic ", __FILE__, __LINE__, #e))
    226 #else
    227 #define	KASSERT(e)	(__predict_true((e)) ? (void)0 :		    \
    228 			    __assert("diagnostic ", __FILE__, __LINE__, "e"))
    229 #endif
    230 #endif
    231 
    232 #ifndef DEBUG
    233 #ifdef lint
    234 #define	KDASSERT(e)	/* NOTHING */
    235 #else /* lint */
    236 #define	KDASSERT(e)	((void)0)
    237 #endif /* lint */
    238 #else
    239 #ifdef __STDC__
    240 #define	KDASSERT(e)	(__predict_true((e)) ? (void)0 :		    \
    241 			    __assert("debugging ", __FILE__, __LINE__, #e))
    242 #else
    243 #define	KDASSERT(e)	(__predict_true((e)) ? (void)0 :		    \
    244 			    __assert("debugging ", __FILE__, __LINE__, "e"))
    245 #endif
    246 #endif
    247 
    248 #ifndef offsetof
    249 #define	offsetof(type, member)	((size_t)(&((type *)0)->member))
    250 #endif
    251 
    252 /* Prototypes for non-quad routines. */
    253 /* XXX notyet #ifdef _STANDALONE */
    254 int	 bcmp __P((const void *, const void *, size_t));
    255 void	 bzero __P((void *, size_t));
    256 /* #endif */
    257 void	 __assert __P((const char *, const char *, int, const char *))
    258 	    __attribute__((__noreturn__));
    259 int	 ffs __P((int));
    260 u_int32_t
    261 	 inet_addr __P((const char *));
    262 char	*intoa __P((u_int32_t));
    263 #define inet_ntoa(a) intoa((a).s_addr)
    264 void	*memchr __P((const void *, int, size_t));
    265 int	 memcmp __P((const void *, const void *, size_t));
    266 void	*memcpy __P((void *, const void *, size_t));
    267 void	*memmove __P((void *, const void *, size_t));
    268 void	*memset __P((void *, int, size_t));
    269 int	 pmatch __P((const char *, const char *, const char **));
    270 u_long	 random __P((void));
    271 int	 scanc __P((u_int, const u_char *, const u_char *, int));
    272 int	 skpc __P((int, size_t, u_char *));
    273 char	*strcat __P((char *, const char *));
    274 char	*strchr __P((const char *, int));
    275 int	 strcmp __P((const char *, const char *));
    276 int	 strcasecmp __P((const char *, const char *));
    277 char	*strcpy __P((char *, const char *));
    278 size_t	 strlen __P((const char *));
    279 int	 strncasecmp __P((const char *, const char *, size_t));
    280 int	 strncmp __P((const char *, const char *, size_t));
    281 char	*strncpy __P((char *, const char *, size_t));
    282 char	*strrchr __P((const char *, int));
    283 u_long	 strtoul __P((const char *, char **, int));
    284 #endif /* !_LIB_LIBKERN_LIBKERN_H_ */
    285