This commit was manufactured by cvs2svn to create tag 'FreeBSD-release/1.0'.
[unix-history] / sys / kern / subr_xxx.c
CommitLineData
15637ed4
RG
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 *
78ed81a3 33 * from: @(#)subr_xxx.c 7.10 (Berkeley) 4/20/91
34 * $Id$
15637ed4
RG
35 */
36
37/*
38 * Miscellaneous trivial functions, including many
39 * that are often inline-expanded or done in assembler.
40 */
41#include "param.h"
42#include "systm.h"
43#include "machine/cpu.h"
44
45/*
46 * Unsupported device function (e.g. writing to read-only device).
47 */
48enodev()
49{
50
51 return (ENODEV);
52}
53
54/*
55 * Unconfigured device function; driver not configured.
56 */
57enxio()
58{
59
60 return (ENXIO);
61}
62
63/*
64 * Unsupported ioctl function.
65 */
66enoioctl()
67{
68
69 return (ENOTTY);
70}
71
72/*
73 * Unsupported system function.
74 * This is used for an otherwise-reasonable operation
75 * that is not supported by the current system binary.
76 */
77enosys()
78{
79
80 return (ENOSYS);
81}
82
83/*
84 * Return error for operation not supported
85 * on a specific object or file type.
86 */
87eopnotsupp()
88{
89
90 return (EOPNOTSUPP);
91}
92
93/*
94 * Generic null operation, always returns success.
95 */
96nullop()
97{
98
99 return (0);
100}
101
102/*
103 * Definitions of various trivial functions;
104 * usually expanded inline rather than being defined here.
105 */
106#ifdef NEED_MINMAX
107imin(a, b)
108 int a, b;
109{
110
111 return (a < b ? a : b);
112}
113
114imax(a, b)
115 int a, b;
116{
117
118 return (a > b ? a : b);
119}
120
121unsigned int
122min(a, b)
123 unsigned int a, b;
124{
125
126 return (a < b ? a : b);
127}
128
129unsigned int
130max(a, b)
131 unsigned int a, b;
132{
133
134 return (a > b ? a : b);
135}
136
137long
138lmin(a, b)
139 long a, b;
140{
141
142 return (a < b ? a : b);
143}
144
145long
146lmax(a, b)
147 long a, b;
148{
149
150 return (a > b ? a : b);
151}
152
153unsigned long
154ulmin(a, b)
155 unsigned long a, b;
156{
157
158 return (a < b ? a : b);
159}
160
161unsigned long
162ulmax(a, b)
163 unsigned long a, b;
164{
165
166 return (a > b ? a : b);
167}
168#endif /* NEED_MINMAX */
169
170#ifdef NEED_FFS
171ffs(mask)
172 register long mask;
173{
174 register int bit;
175
176 if (!mask)
177 return(0);
178 for (bit = 1;; ++bit) {
179 if (mask&0x01)
180 return(bit);
181 mask >>= 1;
182 }
183}
184#endif /* NEED_FFS */
185
186#ifdef NEED_BCMP
187bcmp(v1, v2, len)
188 void *v1, *v2;
189 register unsigned len;
190{
191 register u_char *s1 = v1, *s2 = v2;
192
193 while (len--)
194 if (*s1++ != *s2++)
195 return (1);
196 return (0);
197}
198#endif /* NEED_BCMP */
199
200#ifdef NEED_STRLEN
201size_t
202strlen(s1)
203 register const char *s1;
204{
205 register size_t len;
206
207 for (len = 0; *s1++ != '\0'; len++)
208 ;
209 return (len);
210}
211#endif /* NEED_STRLEN */