|
|
1.1 root 1: /*
2: * Copyright (c) 1982, 1986, 1991 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms, with or without
6: * modification, are permitted provided that the following conditions
7: * are met:
8: * 1. Redistributions of source code must retain the above copyright
9: * notice, this list of conditions and the following disclaimer.
10: * 2. Redistributions in binary form must reproduce the above copyright
11: * notice, this list of conditions and the following disclaimer in the
12: * documentation and/or other materials provided with the distribution.
13: * 3. All advertising materials mentioning features or use of this software
14: * must display the following acknowledgement:
15: * This product includes software developed by the University of
16: * California, Berkeley and its contributors.
17: * 4. Neither the name of the University nor the names of its contributors
18: * may be used to endorse or promote products derived from this software
19: * without specific prior written permission.
20: *
21: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31: * SUCH DAMAGE.
32: *
33: * @(#)subr_xxx.c 7.10 (Berkeley) 4/20/91
34: */
35:
36: /*
37: * Miscellaneous trivial functions, including many
38: * that are often inline-expanded or done in assembler.
39: */
40: #include "param.h"
41: #include "systm.h"
42: #include "machine/cpu.h"
43:
44: /*
45: * Unsupported device function (e.g. writing to read-only device).
46: */
47: enodev()
48: {
49:
50: return (ENODEV);
51: }
52:
53: /*
54: * Unconfigured device function; driver not configured.
55: */
56: enxio()
57: {
58:
59: return (ENXIO);
60: }
61:
62: /*
63: * Unsupported ioctl function.
64: */
65: enoioctl()
66: {
67:
68: return (ENOTTY);
69: }
70:
71: /*
72: * Unsupported system function.
73: * This is used for an otherwise-reasonable operation
74: * that is not supported by the current system binary.
75: */
76: enosys()
77: {
78:
79: return (ENOSYS);
80: }
81:
82: /*
83: * Return error for operation not supported
84: * on a specific object or file type.
85: */
86: eopnotsupp()
87: {
88:
89: return (EOPNOTSUPP);
90: }
91:
92: /*
93: * Generic null operation, always returns success.
94: */
95: nullop()
96: {
97:
98: return (0);
99: }
100:
101: /*
102: * Definitions of various trivial functions;
103: * usually expanded inline rather than being defined here.
104: */
105: #ifdef NEED_MINMAX
106: imin(a, b)
107: int a, b;
108: {
109:
110: return (a < b ? a : b);
111: }
112:
113: imax(a, b)
114: int a, b;
115: {
116:
117: return (a > b ? a : b);
118: }
119:
120: unsigned int
121: min(a, b)
122: unsigned int a, b;
123: {
124:
125: return (a < b ? a : b);
126: }
127:
128: unsigned int
129: max(a, b)
130: unsigned int a, b;
131: {
132:
133: return (a > b ? a : b);
134: }
135:
136: long
137: lmin(a, b)
138: long a, b;
139: {
140:
141: return (a < b ? a : b);
142: }
143:
144: long
145: lmax(a, b)
146: long a, b;
147: {
148:
149: return (a > b ? a : b);
150: }
151:
152: unsigned long
153: ulmin(a, b)
154: unsigned long a, b;
155: {
156:
157: return (a < b ? a : b);
158: }
159:
160: unsigned long
161: ulmax(a, b)
162: unsigned long a, b;
163: {
164:
165: return (a > b ? a : b);
166: }
167: #endif /* NEED_MINMAX */
168:
169: #ifdef NEED_FFS
170: ffs(mask)
171: register long mask;
172: {
173: register int bit;
174:
175: if (!mask)
176: return(0);
177: for (bit = 1;; ++bit) {
178: if (mask&0x01)
179: return(bit);
180: mask >>= 1;
181: }
182: }
183: #endif /* NEED_FFS */
184:
185: #ifdef NEED_BCMP
186: bcmp(v1, v2, len)
187: void *v1, *v2;
188: register unsigned len;
189: {
190: register u_char *s1 = v1, *s2 = v2;
191:
192: while (len--)
193: if (*s1++ != *s2++)
194: return (1);
195: return (0);
196: }
197: #endif /* NEED_BCMP */
198:
199: #ifdef NEED_STRLEN
200: strlen(s1)
201: register char *s1;
202: {
203: register int len;
204:
205: for (len = 0; *s1++ != '\0'; len++)
206: ;
207: return (len);
208: }
209: #endif /* NEED_STRLEN */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.