|
|
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: *
1.1.1.5 ! root 33: * from: @(#)kern_subr.c 7.7 (Berkeley) 4/15/91
! 34: * kern_subr.c,v 1.5 1993/06/27 06:01:45 andrew Exp
1.1 root 35: */
36:
37: #include "param.h"
38: #include "systm.h"
39: #include "proc.h"
40:
1.1.1.5 ! root 41: int
1.1 root 42: uiomove(cp, n, uio)
43: register caddr_t cp;
44: register int n;
45: register struct uio *uio;
46: {
47: register struct iovec *iov;
48: u_int cnt;
49: int error = 0;
50:
51:
52: #ifdef DIAGNOSTIC
53: if (uio->uio_rw != UIO_READ && uio->uio_rw != UIO_WRITE)
54: panic("uiomove: mode");
55: if (uio->uio_segflg == UIO_USERSPACE && uio->uio_procp != curproc)
56: panic("uiomove proc");
57: #endif
58: while (n > 0 && uio->uio_resid) {
59: iov = uio->uio_iov;
60: cnt = iov->iov_len;
61: if (cnt == 0) {
62: uio->uio_iov++;
63: uio->uio_iovcnt--;
64: continue;
65: }
66: if (cnt > n)
67: cnt = n;
68: switch (uio->uio_segflg) {
69:
70: case UIO_USERSPACE:
71: case UIO_USERISPACE:
72: if (uio->uio_rw == UIO_READ)
73: error = copyout(cp, iov->iov_base, cnt);
74: else
75: error = copyin(iov->iov_base, cp, cnt);
76: if (error)
77: return (error);
78: break;
79:
80: case UIO_SYSSPACE:
81: if (uio->uio_rw == UIO_READ)
82: bcopy((caddr_t)cp, iov->iov_base, cnt);
83: else
84: bcopy(iov->iov_base, (caddr_t)cp, cnt);
85: break;
86: }
87: iov->iov_base += cnt;
88: iov->iov_len -= cnt;
89: uio->uio_resid -= cnt;
90: uio->uio_offset += cnt;
91: cp += cnt;
92: n -= cnt;
93: }
94: return (error);
95: }
96:
1.1.1.5 ! root 97: int
1.1.1.2 root 98: uioapply(func, arg1, arg2, uio)
1.1.1.5 ! root 99: int (*func)();
! 100: int arg1, arg2;
1.1.1.2 root 101: register struct uio *uio;
102: {
103: register struct iovec *iov;
104: u_int cnt, cnt1;
105: int error = 0;
106:
107:
108: /*#ifdef DIAGNOSTIC*/
109: if (uio->uio_rw != UIO_READ && uio->uio_rw != UIO_WRITE)
110: panic("uioapply: mode");
111: if (uio->uio_segflg == UIO_USERSPACE && uio->uio_procp != curproc)
112: panic("uioapply proc");
113: /*#endif*/
114: while (uio->uio_resid) {
115: iov = uio->uio_iov;
116: cnt = iov->iov_len;
117: if (cnt == 0) {
118: uio->uio_iov++;
119: uio->uio_iovcnt--;
120: continue;
121: }
122: cnt1 = cnt;
123: error = (*func)(arg1, arg2, uio->uio_offset, uio->uio_rw,
124: iov->iov_base, &cnt1, uio->uio_procp);
125: cnt -= cnt1;
126: iov->iov_base += cnt;
127: iov->iov_len -= cnt;
128: uio->uio_resid -= cnt;
129: uio->uio_offset += cnt;
130: if (error || cnt1)
131: return (error);
132: }
133: return (0);
134: }
135:
1.1 root 136: /*
137: * Give next character to user as result of read.
138: */
1.1.1.5 ! root 139: int
1.1 root 140: ureadc(c, uio)
141: register int c;
142: register struct uio *uio;
143: {
144: register struct iovec *iov;
145:
146: again:
147: if (uio->uio_iovcnt == 0)
148: panic("ureadc");
149: iov = uio->uio_iov;
150: if (iov->iov_len <= 0 || uio->uio_resid <= 0) {
151: uio->uio_iovcnt--;
152: uio->uio_iov++;
153: goto again;
154: }
155: switch (uio->uio_segflg) {
156:
157: case UIO_USERSPACE:
158: if (subyte(iov->iov_base, c) < 0)
159: return (EFAULT);
160: break;
161:
162: case UIO_SYSSPACE:
163: *iov->iov_base = c;
164: break;
165:
166: case UIO_USERISPACE:
167: if (suibyte(iov->iov_base, c) < 0)
168: return (EFAULT);
169: break;
170: }
171: iov->iov_base++;
172: iov->iov_len--;
173: uio->uio_resid--;
174: uio->uio_offset++;
175: return (0);
176: }
177:
1.1.1.5 ! root 178: char *
! 179: #ifdef __STDC__
! 180: strcat(char *src, const char *append)
! 181: #else
1.1 root 182: strcat(src, append)
183: register char *src, *append;
1.1.1.5 ! root 184: #endif
1.1 root 185: {
186: for (; *src; ++src)
187: ;
188: while (*src++ = *append++)
189: ;
1.1.1.5 ! root 190: return src;
1.1 root 191: }
192:
1.1.1.5 ! root 193: char *
! 194: #ifdef __STDC__
! 195: strcpy(char *to, const char *from)
! 196: #else
1.1 root 197: strcpy(to, from)
198: register char *to, *from;
1.1.1.5 ! root 199: #endif
1.1 root 200: {
1.1.1.5 ! root 201: while (*to++ = *from++)
1.1 root 202: ;
1.1.1.5 ! root 203:
! 204: return to;
1.1 root 205: }
206:
1.1.1.5 ! root 207: char *
! 208: #ifdef __STDC__
! 209: strncpy(char *to, const char *from, int cnt)
! 210: #else
1.1 root 211: strncpy(to, from, cnt)
212: register char *to, *from;
213: register int cnt;
1.1.1.5 ! root 214: #endif
1.1 root 215: {
216: for (; cnt && (*to = *from); --cnt, ++from, ++to)
217: ;
218: *to = '\0';
1.1.1.5 ! root 219:
! 220: return to;
1.1 root 221: }
222:
1.1.1.4 root 223:
224: int
225: strcmp(s1, s2)
226: register const char *s1, *s2;
227: {
228: while (*s1 == *s2++)
229: if (*s1++ == 0)
230: return (0);
231: return (*(unsigned char *)s1 - *(unsigned char *)--s2);
232: }
233:
1.1 root 234: #ifndef lint /* unused except by ct.c, other oddities XXX */
235: /*
236: * Get next character written in by user from uio.
237: */
1.1.1.5 ! root 238: int
1.1 root 239: uwritec(uio)
240: struct uio *uio;
241: {
242: register struct iovec *iov;
243: register int c;
244:
245: if (uio->uio_resid <= 0)
246: return (-1);
247: again:
248: if (uio->uio_iovcnt <= 0)
249: panic("uwritec");
250: iov = uio->uio_iov;
251: if (iov->iov_len == 0) {
252: uio->uio_iov++;
253: if (--uio->uio_iovcnt == 0)
254: return (-1);
255: goto again;
256: }
257: switch (uio->uio_segflg) {
258:
259: case UIO_USERSPACE:
260: c = fubyte(iov->iov_base);
261: break;
262:
263: case UIO_SYSSPACE:
264: c = *(u_char *) iov->iov_base;
265: break;
266:
267: case UIO_USERISPACE:
268: c = fuibyte(iov->iov_base);
269: break;
270: }
271: if (c < 0)
272: return (-1);
273: iov->iov_base++;
274: iov->iov_len--;
275: uio->uio_resid--;
276: uio->uio_offset++;
277: return (c);
278: }
279: #endif /* notdef */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.