| 1 | /* |
| 2 | * Copyright (c) 1982, 1986, 1991 Regents of the University of California. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * %sccs.include.redist.c% |
| 6 | * |
| 7 | * @(#)subr_xxx.c 7.10 (Berkeley) %G% |
| 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * Miscellaneous trivial functions, including many |
| 12 | * that are often inline-expanded or done in assembler. |
| 13 | */ |
| 14 | #include "param.h" |
| 15 | #include "systm.h" |
| 16 | #include "machine/cpu.h" |
| 17 | |
| 18 | /* |
| 19 | * Unsupported device function (e.g. writing to read-only device). |
| 20 | */ |
| 21 | enodev() |
| 22 | { |
| 23 | |
| 24 | return (ENODEV); |
| 25 | } |
| 26 | |
| 27 | /* |
| 28 | * Unconfigured device function; driver not configured. |
| 29 | */ |
| 30 | enxio() |
| 31 | { |
| 32 | |
| 33 | return (ENXIO); |
| 34 | } |
| 35 | |
| 36 | /* |
| 37 | * Unsupported ioctl function. |
| 38 | */ |
| 39 | enoioctl() |
| 40 | { |
| 41 | |
| 42 | return (ENOTTY); |
| 43 | } |
| 44 | |
| 45 | /* |
| 46 | * Unsupported system function. |
| 47 | * This is used for an otherwise-reasonable operation |
| 48 | * that is not supported by the current system binary. |
| 49 | */ |
| 50 | enosys() |
| 51 | { |
| 52 | |
| 53 | return (ENOSYS); |
| 54 | } |
| 55 | |
| 56 | /* |
| 57 | * Return error for operation not supported |
| 58 | * on a specific object or file type. |
| 59 | */ |
| 60 | eopnotsupp() |
| 61 | { |
| 62 | |
| 63 | return (EOPNOTSUPP); |
| 64 | } |
| 65 | |
| 66 | /* |
| 67 | * Generic null operation, always returns success. |
| 68 | */ |
| 69 | nullop() |
| 70 | { |
| 71 | |
| 72 | return (0); |
| 73 | } |
| 74 | |
| 75 | /* |
| 76 | * Definitions of various trivial functions; |
| 77 | * usually expanded inline rather than being defined here. |
| 78 | */ |
| 79 | #ifdef NEED_MINMAX |
| 80 | imin(a, b) |
| 81 | int a, b; |
| 82 | { |
| 83 | |
| 84 | return (a < b ? a : b); |
| 85 | } |
| 86 | |
| 87 | imax(a, b) |
| 88 | int a, b; |
| 89 | { |
| 90 | |
| 91 | return (a > b ? a : b); |
| 92 | } |
| 93 | |
| 94 | unsigned int |
| 95 | min(a, b) |
| 96 | unsigned int a, b; |
| 97 | { |
| 98 | |
| 99 | return (a < b ? a : b); |
| 100 | } |
| 101 | |
| 102 | unsigned int |
| 103 | max(a, b) |
| 104 | unsigned int a, b; |
| 105 | { |
| 106 | |
| 107 | return (a > b ? a : b); |
| 108 | } |
| 109 | |
| 110 | long |
| 111 | lmin(a, b) |
| 112 | long a, b; |
| 113 | { |
| 114 | |
| 115 | return (a < b ? a : b); |
| 116 | } |
| 117 | |
| 118 | long |
| 119 | lmax(a, b) |
| 120 | long a, b; |
| 121 | { |
| 122 | |
| 123 | return (a > b ? a : b); |
| 124 | } |
| 125 | |
| 126 | unsigned long |
| 127 | ulmin(a, b) |
| 128 | unsigned long a, b; |
| 129 | { |
| 130 | |
| 131 | return (a < b ? a : b); |
| 132 | } |
| 133 | |
| 134 | unsigned long |
| 135 | ulmax(a, b) |
| 136 | unsigned long a, b; |
| 137 | { |
| 138 | |
| 139 | return (a > b ? a : b); |
| 140 | } |
| 141 | #endif /* NEED_MINMAX */ |
| 142 | |
| 143 | #ifdef NEED_FFS |
| 144 | ffs(mask) |
| 145 | register long mask; |
| 146 | { |
| 147 | register int bit; |
| 148 | |
| 149 | if (!mask) |
| 150 | return(0); |
| 151 | for (bit = 1;; ++bit) { |
| 152 | if (mask&0x01) |
| 153 | return(bit); |
| 154 | mask >>= 1; |
| 155 | } |
| 156 | } |
| 157 | #endif /* NEED_FFS */ |
| 158 | |
| 159 | #ifdef NEED_BCMP |
| 160 | bcmp(v1, v2, len) |
| 161 | void *v1, *v2; |
| 162 | register unsigned len; |
| 163 | { |
| 164 | register u_char *s1 = v1, *s2 = v2; |
| 165 | |
| 166 | while (len--) |
| 167 | if (*s1++ != *s2++) |
| 168 | return (1); |
| 169 | return (0); |
| 170 | } |
| 171 | #endif /* NEED_BCMP */ |
| 172 | |
| 173 | #ifdef NEED_STRLEN |
| 174 | strlen(s1) |
| 175 | register char *s1; |
| 176 | { |
| 177 | register int len; |
| 178 | |
| 179 | for (len = 0; *s1++ != '\0'; len++) |
| 180 | ; |
| 181 | return (len); |
| 182 | } |
| 183 | #endif /* NEED_STRLEN */ |