Home | History | Annotate | Line # | Download | only in libkern
libkern.h revision 1.23
      1 /*	$NetBSD: libkern.h,v 1.23 1998/07/31 23:44:41 perry 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 #include <sys/types.h>
     39 
     40 #ifndef LIBKERN_INLINE
     41 #define LIBKERN_INLINE	static __inline
     42 #define LIBKERN_BODY
     43 #endif
     44 
     45 LIBKERN_INLINE int imax __P((int, int)) __attribute__ ((unused));
     46 LIBKERN_INLINE int imin __P((int, int)) __attribute__ ((unused));
     47 LIBKERN_INLINE u_int max __P((u_int, u_int)) __attribute__ ((unused));
     48 LIBKERN_INLINE u_int min __P((u_int, u_int)) __attribute__ ((unused));
     49 LIBKERN_INLINE long lmax __P((long, long)) __attribute__ ((unused));
     50 LIBKERN_INLINE long lmin __P((long, long)) __attribute__ ((unused));
     51 LIBKERN_INLINE u_long ulmax __P((u_long, u_long)) __attribute__ ((unused));
     52 LIBKERN_INLINE u_long ulmin __P((u_long, u_long)) __attribute__ ((unused));
     53 LIBKERN_INLINE int abs __P((int)) __attribute__ ((unused));
     54 
     55 #ifdef LIBKERN_BODY
     56 LIBKERN_INLINE int
     57 imax(a, b)
     58 	int a, b;
     59 {
     60 	return (a > b ? a : b);
     61 }
     62 LIBKERN_INLINE int
     63 imin(a, b)
     64 	int a, b;
     65 {
     66 	return (a < b ? a : b);
     67 }
     68 LIBKERN_INLINE long
     69 lmax(a, b)
     70 	long a, b;
     71 {
     72 	return (a > b ? a : b);
     73 }
     74 LIBKERN_INLINE long
     75 lmin(a, b)
     76 	long a, b;
     77 {
     78 	return (a < b ? a : b);
     79 }
     80 LIBKERN_INLINE u_int
     81 max(a, b)
     82 	u_int a, b;
     83 {
     84 	return (a > b ? a : b);
     85 }
     86 LIBKERN_INLINE u_int
     87 min(a, b)
     88 	u_int a, b;
     89 {
     90 	return (a < b ? a : b);
     91 }
     92 LIBKERN_INLINE u_long
     93 ulmax(a, b)
     94 	u_long a, b;
     95 {
     96 	return (a > b ? a : b);
     97 }
     98 LIBKERN_INLINE u_long
     99 ulmin(a, b)
    100 	u_long a, b;
    101 {
    102 	return (a < b ? a : b);
    103 }
    104 
    105 LIBKERN_INLINE int
    106 abs(j)
    107 	int j;
    108 {
    109 	return(j < 0 ? -j : j);
    110 }
    111 #endif
    112 
    113 #ifdef NDEBUG						/* tradition! */
    114 #define	assert(e)	((void)0)
    115 #else
    116 #ifdef __STDC__
    117 #define	assert(e)	((e) ? (void)0 :				    \
    118 			    __assert("", __FILE__, __LINE__, #e))
    119 #else
    120 #define	assert(e)	((e) ? (void)0 :				    \
    121 			    __assert("", __FILE__, __LINE__, "e"))
    122 #endif
    123 #endif
    124 
    125 #ifndef DIAGNOSTIC
    126 #define	KASSERT(e)	((void)0)
    127 #else
    128 #ifdef __STDC__
    129 #define	KASSERT(e)	((e) ? (void)0 :				    \
    130 			    __assert("diagnostic ", __FILE__, __LINE__, #e))
    131 #else
    132 #define	KASSERT(e)	((e) ? (void)0 :				    \
    133 			    __assert("diagnostic ", __FILE__, __LINE__, "e"))
    134 #endif
    135 #endif
    136 
    137 #ifndef DEBUG
    138 #define	KDASSERT(e)	((void)0)
    139 #else
    140 #ifdef __STDC__
    141 #define	KDASSERT(e)	((e) ? (void)0 :				    \
    142 			    __assert("debugging ", __FILE__, __LINE__, #e))
    143 #else
    144 #define	KDASSERT(e)	((e) ? (void)0 :				    \
    145 			    __assert("debugging ", __FILE__, __LINE__, "e"))
    146 #endif
    147 #endif
    148 
    149 #define	offsetof(type, member)	((size_t)(&((type *)0)->member))
    150 
    151 /* Prototypes for non-quad routines. */
    152 void	 __assert __P((const char *, const char *, int, const char *))
    153 	    __attribute__((__noreturn__));
    154 int	 bcmp __P((const void *, const void *, size_t));
    155 void	 bzero __P((void *, size_t));
    156 int	 ffs __P((int));
    157 void	*memchr __P((const void *, int, size_t));
    158 void	*memcpy __P((void *, const void *, size_t));
    159 void	*memmove __P((void *, const void *, size_t));
    160 void	*memset __P((void *, int, size_t));
    161 int	 pmatch __P((const char *, const char *, const char **));
    162 u_long	 random __P((void));
    163 int	 scanc __P((u_int, const u_char *, const u_char *, int));
    164 int	 skpc __P((int, size_t, u_char *));
    165 char	*strcat __P((char *, const char *));
    166 char	*strchr __P((const char *, int));
    167 int	 strcmp __P((const char *, const char *));
    168 char	*strcpy __P((char *, const char *));
    169 size_t	 strlen __P((const char *));
    170 int	 strncmp __P((const char *, const char *, size_t));
    171 char	*strncpy __P((char *, const char *, size_t));
    172 char	*strrchr __P((const char *, int));
    173 int	 strncasecmp __P((const char *, const char *, size_t));
    174