more lint
[unix-history] / usr / src / sys / kern / subr_xxx.c
CommitLineData
b32450f4 1/* subr_xxx.c 4.19 82/10/17 */
ae9e2121
BJ
2
3#include "../h/param.h"
4#include "../h/systm.h"
5#include "../h/conf.h"
6#include "../h/inode.h"
7#include "../h/dir.h"
8#include "../h/user.h"
9#include "../h/buf.h"
10#include "../h/proc.h"
6459ebe0 11#include "../h/fs.h"
cb99a88a
BJ
12#include "../h/vm.h"
13#include "../h/pte.h"
14#include "../h/cmap.h"
d6d7360b 15#include "../h/uio.h"
ae9e2121 16
ae9e2121 17/*
50a84b40 18 * Routine placed in illegal entries in the bdevsw and cdevsw tables.
ae9e2121
BJ
19 */
20nodev()
21{
22
50a84b40 23 return (ENODEV);
ae9e2121
BJ
24}
25
26/*
27 * Null routine; placed in insignificant entries
28 * in the bdevsw and cdevsw tables.
29 */
30nulldev()
31{
32
50a84b40 33 return (0);
ae9e2121
BJ
34}
35
36imin(a, b)
37{
38
39 return (a < b ? a : b);
40}
41
42imax(a, b)
43{
44
45 return (a > b ? a : b);
46}
47
6459ebe0
KM
48unsigned
49min(a, b)
b32450f4 50 u_int a, b;
6459ebe0
KM
51{
52
53 return (a < b ? a : b);
54}
55
56unsigned
57max(a, b)
b32450f4 58 u_int a, b;
6459ebe0
KM
59{
60
61 return (a > b ? a : b);
62}
b32450f4 63
cb99a88a
BJ
64extern cabase, calimit;
65extern struct pte camap[];
66
67caddr_t cacur = (caddr_t)&cabase;
68caddr_t camax = (caddr_t)&cabase;
69int cax = 0;
70/*
71 * This is a kernel-mode storage allocator.
72 * It is very primitive, currently, in that
73 * there is no way to give space back.
74 * It serves, for the time being, the needs of
75 * auto-configuration code and the like which
76 * need to allocate some stuff at boot time.
77 */
78caddr_t
79calloc(size)
80 int size;
81{
82 register caddr_t res;
83 register int i;
84
85 if (cacur+size >= (caddr_t)&calimit)
86 panic("calloc");
87 while (cacur+size > camax) {
88 (void) vmemall(&camap[cax], CLSIZE, &proc[0], CSYS);
89 vmaccess(&camap[cax], camax, CLSIZE);
90 for (i = 0; i < CLSIZE; i++)
91 clearseg(camap[cax++].pg_pfnum);
92 camax += NBPG * CLSIZE;
93 }
94 res = cacur;
95 cacur += size;
96 return (res);
97}
febd1daa 98
cb99a88a
BJ
99#ifndef vax
100ffs(mask)
101 register long mask;
102{
103 register int i;
104
105 for(i=1; i<NSIG; i++) {
106 if (mask & 1)
107 return (i);
108 mask >>= 1;
109 }
110 return (0);
111}
febd1daa 112
4147b3f6
BJ
113ffs(mask)
114 register long mask;
115{
116 register int i;
117
118 for(i=1; i<NSIG; i++) {
119 if (mask & 1)
120 return (i);
121 mask >>= 1;
122 }
123 return (0);
124}
4147b3f6 125
febd1daa
BJ
126bcmp(s1, s2, len)
127 register char *s1, *s2;
128 register int len;
129{
130
131 while (--len)
132 if (*s1++ != *s2++)
133 return (1);
134 return (0);
135}
136
137strlen(s1)
138 register char *s1;
139{
140 register int len;
141
142 for (len = 0; *s1++ != '\0'; len++)
143 /* void */;
144 return (len);
145}
146#endif
d6d7360b 147
d6d7360b
BJ
148/*
149 * Pass back c to the user.
150 */
151passuc(c, uio)
152 register c;
153 struct uio *uio;
154{
155 register struct iovec *iov = uio->uio_iov;
d6d7360b
BJ
156
157 switch (uio->uio_segflg) {
158
159 case 0:
160 if (subyte(iov->iov_base, c) < 0)
161 goto fault;
162 break;
163
164 case 1:
165 *iov->iov_base = c;
166 break;
167
168 case 2:
169 if (suibyte(iov->iov_base, c) < 0)
170 goto fault;
171 break;
172 }
173 iov->iov_base++;
174 iov->iov_len--;
175 uio->uio_resid--;
176 uio->uio_offset++;
177 if (iov->iov_len <= 0) {
178 uio->uio_iov++;
179 uio->uio_iovcnt--;
180 }
181 return (0);
182fault:
183 return (EFAULT);
184}