xref: /netbsd-src/sys/lib/libkern/libkern.h (revision 2a399c6883d870daece976daec6ffa7bb7f934ce)
1 /*	$NetBSD: libkern.h,v 1.15 1997/10/24 18:10:32 mjacob 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.1 (Berkeley) 6/10/93
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 /* Prototypes for non-quad routines. */
150 void	 __assert __P((const char *, const char *, int, const char *))
151 	    __attribute__((__noreturn__));
152 int	 bcmp __P((const void *, const void *, size_t));
153 void	 bzero __P((void *, size_t));
154 int	 ffs __P((int));
155 void	*memchr __P((const void *, int, size_t));
156 u_long	 random __P((void));
157 char	*rindex __P((const char *, int));
158 int	 scanc __P((u_int, const u_char *, const u_char *, int));
159 int	 skpc __P((int, size_t, u_char *));
160 size_t	 strlen __P((const char *));
161 char	*strcat __P((char *, const char *));
162 char	*strcpy __P((char *, const char *));
163 char	*strncpy __P((char *, const char *, size_t));
164 char	*strchr __P((const char *, int));
165 int	 strcmp __P((const char *, const char *));
166 int	 strncmp __P((const char *, const char *, size_t));
167 int	 strncasecmp __P((const char *, const char *, size_t));
168