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