xref: /netbsd-src/sys/lib/libkern/libkern.h (revision 5aefcfdc06931dd97e76246d2fe0302f7b3fe094)
1 /*	$NetBSD: libkern.h,v 1.32 2000/11/01 19:37:18 thorpej 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 #ifdef LIBKERN_BODY
59 LIBKERN_INLINE int
60 imax(a, b)
61 	int a, b;
62 {
63 	return (a > b ? a : b);
64 }
65 LIBKERN_INLINE int
66 imin(a, b)
67 	int a, b;
68 {
69 	return (a < b ? a : b);
70 }
71 LIBKERN_INLINE long
72 lmax(a, b)
73 	long a, b;
74 {
75 	return (a > b ? a : b);
76 }
77 LIBKERN_INLINE long
78 lmin(a, b)
79 	long a, b;
80 {
81 	return (a < b ? a : b);
82 }
83 LIBKERN_INLINE u_int
84 max(a, b)
85 	u_int a, b;
86 {
87 	return (a > b ? a : b);
88 }
89 LIBKERN_INLINE u_int
90 min(a, b)
91 	u_int a, b;
92 {
93 	return (a < b ? a : b);
94 }
95 LIBKERN_INLINE u_long
96 ulmax(a, b)
97 	u_long a, b;
98 {
99 	return (a > b ? a : b);
100 }
101 LIBKERN_INLINE u_long
102 ulmin(a, b)
103 	u_long a, b;
104 {
105 	return (a < b ? a : b);
106 }
107 
108 LIBKERN_INLINE int
109 abs(j)
110 	int j;
111 {
112 	return(j < 0 ? -j : j);
113 }
114 #endif
115 
116 #ifdef NDEBUG						/* tradition! */
117 #define	assert(e)	((void)0)
118 #else
119 #ifdef __STDC__
120 #define	assert(e)	(__predict_true((e)) ? (void)0 :		    \
121 			    __assert("", __FILE__, __LINE__, #e))
122 #else
123 #define	assert(e)	(__predict_true((e)) ? (void)0 :		    \
124 			    __assert("", __FILE__, __LINE__, "e"))
125 #endif
126 #endif
127 
128 #ifndef DIAGNOSTIC
129 #define	KASSERT(e)	((void)0)
130 #else
131 #ifdef __STDC__
132 #define	KASSERT(e)	(__predict_true((e)) ? (void)0 :		    \
133 			    __assert("diagnostic ", __FILE__, __LINE__, #e))
134 #else
135 #define	KASSERT(e)	(__predict_true((e)) ? (void)0 :		    \
136 			    __assert("diagnostic ", __FILE__, __LINE__, "e"))
137 #endif
138 #endif
139 
140 #ifndef DEBUG
141 #define	KDASSERT(e)	((void)0)
142 #else
143 #ifdef __STDC__
144 #define	KDASSERT(e)	(__predict_true((e)) ? (void)0 :		    \
145 			    __assert("debugging ", __FILE__, __LINE__, #e))
146 #else
147 #define	KDASSERT(e)	(__predict_true((e)) ? (void)0 :		    \
148 			    __assert("debugging ", __FILE__, __LINE__, "e"))
149 #endif
150 #endif
151 
152 #ifndef offsetof
153 #define	offsetof(type, member)	((size_t)(&((type *)0)->member))
154 #endif
155 
156 /* Prototypes for non-quad routines. */
157 void	 __assert __P((const char *, const char *, int, const char *))
158 	    __attribute__((__noreturn__));
159 int	 bcmp __P((const void *, const void *, size_t));
160 void	 bzero __P((void *, size_t));
161 int	 ffs __P((int));
162 u_int32_t
163 	 inet_addr __P((const char *));
164 char	*intoa __P((u_int32_t));
165 #define inet_ntoa(a) intoa((a).s_addr)
166 void	*memchr __P((const void *, int, size_t));
167 int	 memcmp __P((const void *, const void *, size_t));
168 void	*memcpy __P((void *, const void *, size_t));
169 void	*memmove __P((void *, const void *, size_t));
170 void	*memset __P((void *, int, size_t));
171 int	 pmatch __P((const char *, const char *, const char **));
172 u_long	 random __P((void));
173 int	 scanc __P((u_int, const u_char *, const u_char *, int));
174 int	 skpc __P((int, size_t, u_char *));
175 char	*strcat __P((char *, const char *));
176 char	*strchr __P((const char *, int));
177 int	 strcmp __P((const char *, const char *));
178 int	 strcasecmp __P((const char *, const char *));
179 char	*strcpy __P((char *, const char *));
180 size_t	 strlen __P((const char *));
181 int	 strncasecmp __P((const char *, const char *, size_t));
182 int	 strncmp __P((const char *, const char *, size_t));
183 char	*strncpy __P((char *, const char *, size_t));
184 char	*strrchr __P((const char *, int));
185 u_long	 strtoul __P((const char *, char **, int));
186 #endif /* !_LIB_LIBKERN_LIBKERN_H_ */
187