Annotation of src/sys/lib/libkern/libkern.h, Revision 1.32.2.4
1.32.2.4! nathanw 1: /* $NetBSD: libkern.h,v 1.32.2.3 2001/08/24 00:11:49 nathanw Exp $ */
1.3 cgd 2:
1.1 cgd 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: *
1.21 fvdl 35: * @(#)libkern.h 8.2 (Berkeley) 8/5/94
1.1 cgd 36: */
37:
1.29 simonb 38: #ifndef _LIB_LIBKERN_LIBKERN_H_
39: #define _LIB_LIBKERN_LIBKERN_H_
40:
1.1 cgd 41: #include <sys/types.h>
1.4 cgd 42:
1.7 christos 43: #ifndef LIBKERN_INLINE
44: #define LIBKERN_INLINE static __inline
45: #define LIBKERN_BODY
46: #endif
47:
1.14 cgd 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));
1.1 cgd 57:
1.32.2.1 nathanw 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:
1.7 christos 68: #ifdef LIBKERN_BODY
69: LIBKERN_INLINE int
1.1 cgd 70: imax(a, b)
71: int a, b;
72: {
73: return (a > b ? a : b);
74: }
1.7 christos 75: LIBKERN_INLINE int
1.1 cgd 76: imin(a, b)
77: int a, b;
78: {
79: return (a < b ? a : b);
80: }
1.7 christos 81: LIBKERN_INLINE long
1.1 cgd 82: lmax(a, b)
83: long a, b;
84: {
85: return (a > b ? a : b);
86: }
1.7 christos 87: LIBKERN_INLINE long
1.1 cgd 88: lmin(a, b)
89: long a, b;
90: {
91: return (a < b ? a : b);
92: }
1.7 christos 93: LIBKERN_INLINE u_int
1.1 cgd 94: max(a, b)
95: u_int a, b;
96: {
97: return (a > b ? a : b);
98: }
1.7 christos 99: LIBKERN_INLINE u_int
1.1 cgd 100: min(a, b)
101: u_int a, b;
102: {
103: return (a < b ? a : b);
104: }
1.7 christos 105: LIBKERN_INLINE u_long
1.1 cgd 106: ulmax(a, b)
107: u_long a, b;
108: {
109: return (a > b ? a : b);
110: }
1.7 christos 111: LIBKERN_INLINE u_long
1.1 cgd 112: ulmin(a, b)
113: u_long a, b;
114: {
115: return (a < b ? a : b);
1.5 leo 116: }
117:
1.7 christos 118: LIBKERN_INLINE int
1.5 leo 119: abs(j)
120: int j;
121: {
122: return(j < 0 ? -j : j);
1.32.2.1 nathanw 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);
1.1 cgd 201: }
1.7 christos 202: #endif
1.1 cgd 203:
1.9 cgd 204: #ifdef NDEBUG /* tradition! */
205: #define assert(e) ((void)0)
1.10 cgd 206: #else
1.9 cgd 207: #ifdef __STDC__
1.30 thorpej 208: #define assert(e) (__predict_true((e)) ? (void)0 : \
1.9 cgd 209: __assert("", __FILE__, __LINE__, #e))
210: #else
1.30 thorpej 211: #define assert(e) (__predict_true((e)) ? (void)0 : \
1.9 cgd 212: __assert("", __FILE__, __LINE__, "e"))
213: #endif
214: #endif
215:
216: #ifndef DIAGNOSTIC
1.32.2.2 nathanw 217: #ifdef lint
218: #define KASSERT(e) /* NOTHING */
219: #else /* !lint */
1.9 cgd 220: #define KASSERT(e) ((void)0)
1.32.2.2 nathanw 221: #endif /* !lint */
1.9 cgd 222: #else
223: #ifdef __STDC__
1.30 thorpej 224: #define KASSERT(e) (__predict_true((e)) ? (void)0 : \
1.9 cgd 225: __assert("diagnostic ", __FILE__, __LINE__, #e))
226: #else
1.30 thorpej 227: #define KASSERT(e) (__predict_true((e)) ? (void)0 : \
1.9 cgd 228: __assert("diagnostic ", __FILE__, __LINE__, "e"))
229: #endif
230: #endif
231:
232: #ifndef DEBUG
1.32.2.2 nathanw 233: #ifdef lint
234: #define KDASSERT(e) /* NOTHING */
235: #else /* lint */
1.9 cgd 236: #define KDASSERT(e) ((void)0)
1.32.2.2 nathanw 237: #endif /* lint */
1.9 cgd 238: #else
239: #ifdef __STDC__
1.30 thorpej 240: #define KDASSERT(e) (__predict_true((e)) ? (void)0 : \
1.9 cgd 241: __assert("debugging ", __FILE__, __LINE__, #e))
242: #else
1.30 thorpej 243: #define KDASSERT(e) (__predict_true((e)) ? (void)0 : \
1.9 cgd 244: __assert("debugging ", __FILE__, __LINE__, "e"))
245: #endif
246: #endif
1.19 thorpej 247:
1.31 msaitoh 248: #ifndef offsetof
1.19 thorpej 249: #define offsetof(type, member) ((size_t)(&((type *)0)->member))
1.31 msaitoh 250: #endif
1.9 cgd 251:
1.1 cgd 252: /* Prototypes for non-quad routines. */
1.32.2.3 nathanw 253: /* XXX notyet #ifdef _STANDALONE */
1.1 cgd 254: int bcmp __P((const void *, const void *, size_t));
1.13 drochner 255: void bzero __P((void *, size_t));
1.32.2.3 nathanw 256: /* #endif */
1.32.2.4! nathanw 257:
! 258: /* Prototypes for which GCC built-ins exist. */
! 259: void *memcpy __P((void *, const void *, size_t));
! 260: int memcmp __P((const void *, const void *, size_t));
! 261: void *memset __P((void *, int, size_t));
! 262: #if __GNUC_PREREQ__(2, 95)
! 263: #define memcpy(d, s, l) __builtin_memcpy(d, s, l)
! 264: #define memcmp(a, b, l) __builtin_memcmp(a, b, l)
! 265: #define memset(d, v, l) __builtin_memset(d, v, l)
! 266: #endif
! 267:
! 268: char *strcpy __P((char *, const char *));
! 269: int strcmp __P((const char *, const char *));
! 270: size_t strlen __P((const char *));
! 271: #if __GNUC_PREREQ__(2, 95)
! 272: #define strcpy(d, s) __builtin_strcpy(d, s)
! 273: #define strcmp(a, b) __builtin_strcmp(a, b)
! 274: #define strlen(a) __builtin_strlen(a)
! 275: #endif
! 276:
! 277: /* Functions for which we always use built-ins. */
! 278: #ifdef __GNUC__
! 279: #define alloca(s) __builtin_alloca(s)
! 280: #endif
! 281:
! 282: /* These exist in GCC 3.x, but we don't bother. */
! 283: char *strcat __P((char *, const char *));
! 284: char *strncpy __P((char *, const char *, size_t));
! 285: int strncmp __P((const char *, const char *, size_t));
! 286: char *strchr __P((const char *, int));
! 287: char *strrchr __P((const char *, int));
! 288:
! 289: /* This exists in GCC 3.x, but we don't bother (yet). */
! 290: int ffs __P((int));
! 291:
1.32.2.3 nathanw 292: void __assert __P((const char *, const char *, int, const char *))
293: __attribute__((__noreturn__));
1.28 simonb 294: u_int32_t
295: inet_addr __P((const char *));
296: char *intoa __P((u_int32_t));
297: #define inet_ntoa(a) intoa((a).s_addr)
1.15 mjacob 298: void *memchr __P((const void *, int, size_t));
1.23 perry 299: void *memmove __P((void *, const void *, size_t));
1.22 christos 300: int pmatch __P((const char *, const char *, const char **));
1.1 cgd 301: u_long random __P((void));
1.11 cgd 302: int scanc __P((u_int, const u_char *, const u_char *, int));
1.7 christos 303: int skpc __P((int, size_t, u_char *));
1.32 thorpej 304: int strcasecmp __P((const char *, const char *));
1.28 simonb 305: int strncasecmp __P((const char *, const char *, size_t));
306: u_long strtoul __P((const char *, char **, int));
1.29 simonb 307: #endif /* !_LIB_LIBKERN_LIBKERN_H_ */
CVSweb <webmaster@jp.NetBSD.org>