1 /* $NetBSD: libkern.h,v 1.9 1996/08/27 00:44:21 cgd 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 46 LIBKERN_INLINE int imax __P((int, int)); 47 LIBKERN_INLINE int imin __P((int, int)); 48 LIBKERN_INLINE u_int max __P((u_int, u_int)); 49 LIBKERN_INLINE u_int min __P((u_int, u_int)); 50 LIBKERN_INLINE long lmax __P((long, long)); 51 LIBKERN_INLINE long lmin __P((long, long)); 52 LIBKERN_INLINE u_long ulmax __P((u_long, u_long)); 53 LIBKERN_INLINE u_long ulmin __P((u_long, u_long)); 54 LIBKERN_INLINE int abs __P((int)); 55 56 #ifdef LIBKERN_BODY 57 LIBKERN_INLINE int 58 imax(a, b) 59 int a, b; 60 { 61 return (a > b ? a : b); 62 } 63 LIBKERN_INLINE int 64 imin(a, b) 65 int a, b; 66 { 67 return (a < b ? a : b); 68 } 69 LIBKERN_INLINE long 70 lmax(a, b) 71 long a, b; 72 { 73 return (a > b ? a : b); 74 } 75 LIBKERN_INLINE long 76 lmin(a, b) 77 long a, b; 78 { 79 return (a < b ? a : b); 80 } 81 LIBKERN_INLINE u_int 82 max(a, b) 83 u_int a, b; 84 { 85 return (a > b ? a : b); 86 } 87 LIBKERN_INLINE u_int 88 min(a, b) 89 u_int a, b; 90 { 91 return (a < b ? a : b); 92 } 93 LIBKERN_INLINE u_long 94 ulmax(a, b) 95 u_long a, b; 96 { 97 return (a > b ? a : b); 98 } 99 LIBKERN_INLINE u_long 100 ulmin(a, b) 101 u_long a, b; 102 { 103 return (a < b ? a : b); 104 } 105 106 LIBKERN_INLINE int 107 abs(j) 108 int j; 109 { 110 return(j < 0 ? -j : j); 111 } 112 #endif 113 114 #ifdef NDEBUG /* tradition! */ 115 #define assert(e) ((void)0) 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 int ffs __P((int)); 154 u_long random __P((void)); 155 char *rindex __P((const char *, int)); 156 int scanc __P((u_int, u_char *, u_char *, int)); 157 int skpc __P((int, size_t, u_char *)); 158 size_t strlen __P((const char *)); 159 char *strcat __P((char *, const char *)); 160 char *strcpy __P((char *, const char *)); 161 char *strncpy __P((char *, const char *, size_t)); 162 int strcmp __P((const char *, const char *)); 163 int strncmp __P((const char *, const char *, size_t)); 164 int strncasecmp __P((const char *, const char *, size_t)); 165