Commit | Line | Data |
---|---|---|
da7c5cc6 | 1 | /* |
d7db4999 MK |
2 | * Copyright (c) 1982, 1986, 1991 Regents of the University of California. |
3 | * All rights reserved. | |
da7c5cc6 | 4 | * |
d7db4999 MK |
5 | * %sccs.include.redist.c% |
6 | * | |
e64c6da2 | 7 | * @(#)subr_xxx.c 7.10 (Berkeley) %G% |
da7c5cc6 | 8 | */ |
961945a8 | 9 | |
d7db4999 MK |
10 | /* |
11 | * Miscellaneous trivial functions, including many | |
12 | * that are often inline-expanded or done in assembler. | |
13 | */ | |
e64c6da2 MK |
14 | #include "param.h" |
15 | #include "systm.h" | |
d7db4999 | 16 | #include "machine/cpu.h" |
ae9e2121 | 17 | |
ae9e2121 | 18 | /* |
d7db4999 | 19 | * Unsupported device function (e.g. writing to read-only device). |
ae9e2121 | 20 | */ |
d7db4999 | 21 | enodev() |
ae9e2121 BJ |
22 | { |
23 | ||
50a84b40 | 24 | return (ENODEV); |
ae9e2121 BJ |
25 | } |
26 | ||
27 | /* | |
d7db4999 MK |
28 | * Unconfigured device function; driver not configured. |
29 | */ | |
30 | enxio() | |
31 | { | |
32 | ||
33 | return (ENXIO); | |
34 | } | |
35 | ||
36 | /* | |
e64c6da2 MK |
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. | |
ae9e2121 | 59 | */ |
d7db4999 MK |
60 | eopnotsupp() |
61 | { | |
62 | ||
63 | return (EOPNOTSUPP); | |
64 | } | |
65 | ||
66 | /* | |
67 | * Generic null operation, always returns success. | |
68 | */ | |
69 | nullop() | |
ae9e2121 BJ |
70 | { |
71 | ||
50a84b40 | 72 | return (0); |
ae9e2121 BJ |
73 | } |
74 | ||
fb1db32c MK |
75 | /* |
76 | * Definitions of various trivial functions; | |
77 | * usually expanded inline rather than being defined here. | |
78 | */ | |
e64c6da2 | 79 | #ifdef NEED_MINMAX |
ae9e2121 | 80 | imin(a, b) |
d7db4999 | 81 | int a, b; |
ae9e2121 BJ |
82 | { |
83 | ||
84 | return (a < b ? a : b); | |
85 | } | |
86 | ||
87 | imax(a, b) | |
d7db4999 | 88 | int a, b; |
ae9e2121 BJ |
89 | { |
90 | ||
91 | return (a > b ? a : b); | |
92 | } | |
93 | ||
d7db4999 | 94 | unsigned int |
6459ebe0 | 95 | min(a, b) |
d7db4999 | 96 | unsigned int a, b; |
6459ebe0 KM |
97 | { |
98 | ||
99 | return (a < b ? a : b); | |
100 | } | |
101 | ||
d7db4999 | 102 | unsigned int |
6459ebe0 | 103 | max(a, b) |
d7db4999 MK |
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; | |
6459ebe0 KM |
137 | { |
138 | ||
139 | return (a > b ? a : b); | |
140 | } | |
e64c6da2 | 141 | #endif /* NEED_MINMAX */ |
b32450f4 | 142 | |
e64c6da2 | 143 | #ifdef NEED_FFS |
cb99a88a BJ |
144 | ffs(mask) |
145 | register long mask; | |
146 | { | |
42c08c41 | 147 | register int bit; |
cb99a88a | 148 | |
42c08c41 KB |
149 | if (!mask) |
150 | return(0); | |
0043ce8e | 151 | for (bit = 1;; ++bit) { |
42c08c41 KB |
152 | if (mask&0x01) |
153 | return(bit); | |
cb99a88a BJ |
154 | mask >>= 1; |
155 | } | |
cb99a88a | 156 | } |
e64c6da2 | 157 | #endif /* NEED_FFS */ |
febd1daa | 158 | |
e64c6da2 | 159 | #ifdef NEED_BCMP |
d7db4999 MK |
160 | bcmp(v1, v2, len) |
161 | void *v1, *v2; | |
9d61b7ff | 162 | register unsigned len; |
febd1daa | 163 | { |
d7db4999 | 164 | register u_char *s1 = v1, *s2 = v2; |
febd1daa | 165 | |
f49dd739 | 166 | while (len--) |
febd1daa BJ |
167 | if (*s1++ != *s2++) |
168 | return (1); | |
169 | return (0); | |
170 | } | |
e64c6da2 | 171 | #endif /* NEED_BCMP */ |
febd1daa | 172 | |
e64c6da2 | 173 | #ifdef NEED_STRLEN |
febd1daa BJ |
174 | strlen(s1) |
175 | register char *s1; | |
176 | { | |
177 | register int len; | |
178 | ||
179 | for (len = 0; *s1++ != '\0'; len++) | |
d7db4999 | 180 | ; |
febd1daa BJ |
181 | return (len); |
182 | } | |
e64c6da2 | 183 | #endif /* NEED_STRLEN */ |