|
|
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: * @(#)kern_subr.c 7.7 (Berkeley) 4/15/91
34: */
35:
36: #include "param.h"
37: #include "systm.h"
38: #include "proc.h"
39:
40: uiomove(cp, n, uio)
41: register caddr_t cp;
42: register int n;
43: register struct uio *uio;
44: {
45: register struct iovec *iov;
46: u_int cnt;
47: int error = 0;
48:
49:
50: #ifdef DIAGNOSTIC
51: if (uio->uio_rw != UIO_READ && uio->uio_rw != UIO_WRITE)
52: panic("uiomove: mode");
53: if (uio->uio_segflg == UIO_USERSPACE && uio->uio_procp != curproc)
54: panic("uiomove proc");
55: #endif
56: while (n > 0 && uio->uio_resid) {
57: iov = uio->uio_iov;
58: cnt = iov->iov_len;
59: if (cnt == 0) {
60: uio->uio_iov++;
61: uio->uio_iovcnt--;
62: continue;
63: }
64: if (cnt > n)
65: cnt = n;
66: switch (uio->uio_segflg) {
67:
68: case UIO_USERSPACE:
69: case UIO_USERISPACE:
70: if (uio->uio_rw == UIO_READ)
71: error = copyout(cp, iov->iov_base, cnt);
72: else
73: error = copyin(iov->iov_base, cp, cnt);
74: if (error)
75: return (error);
76: break;
77:
78: case UIO_SYSSPACE:
79: if (uio->uio_rw == UIO_READ)
80: bcopy((caddr_t)cp, iov->iov_base, cnt);
81: else
82: bcopy(iov->iov_base, (caddr_t)cp, cnt);
83: break;
84: }
85: iov->iov_base += cnt;
86: iov->iov_len -= cnt;
87: uio->uio_resid -= cnt;
88: uio->uio_offset += cnt;
89: cp += cnt;
90: n -= cnt;
91: }
92: return (error);
93: }
94:
95: /*
96: * Give next character to user as result of read.
97: */
98: ureadc(c, uio)
99: register int c;
100: register struct uio *uio;
101: {
102: register struct iovec *iov;
103:
104: again:
105: if (uio->uio_iovcnt == 0)
106: panic("ureadc");
107: iov = uio->uio_iov;
108: if (iov->iov_len <= 0 || uio->uio_resid <= 0) {
109: uio->uio_iovcnt--;
110: uio->uio_iov++;
111: goto again;
112: }
113: switch (uio->uio_segflg) {
114:
115: case UIO_USERSPACE:
116: if (subyte(iov->iov_base, c) < 0)
117: return (EFAULT);
118: break;
119:
120: case UIO_SYSSPACE:
121: *iov->iov_base = c;
122: break;
123:
124: case UIO_USERISPACE:
125: if (suibyte(iov->iov_base, c) < 0)
126: return (EFAULT);
127: break;
128: }
129: iov->iov_base++;
130: iov->iov_len--;
131: uio->uio_resid--;
132: uio->uio_offset++;
133: return (0);
134: }
135:
136: strcat(src, append)
137: register char *src, *append;
138: {
139:
140: for (; *src; ++src)
141: ;
142: while (*src++ = *append++)
143: ;
144: }
145:
146: strcpy(to, from)
147: register char *to, *from;
148: {
149:
150: for (; *from = *to; ++from, ++to)
151: ;
152: }
153:
154: strncpy(to, from, cnt)
155: register char *to, *from;
156: register int cnt;
157: {
158:
159: for (; cnt && (*to = *from); --cnt, ++from, ++to)
160: ;
161: *to = '\0';
162: }
163:
164: #ifndef lint /* unused except by ct.c, other oddities XXX */
165: /*
166: * Get next character written in by user from uio.
167: */
168: uwritec(uio)
169: struct uio *uio;
170: {
171: register struct iovec *iov;
172: register int c;
173:
174: if (uio->uio_resid <= 0)
175: return (-1);
176: again:
177: if (uio->uio_iovcnt <= 0)
178: panic("uwritec");
179: iov = uio->uio_iov;
180: if (iov->iov_len == 0) {
181: uio->uio_iov++;
182: if (--uio->uio_iovcnt == 0)
183: return (-1);
184: goto again;
185: }
186: switch (uio->uio_segflg) {
187:
188: case UIO_USERSPACE:
189: c = fubyte(iov->iov_base);
190: break;
191:
192: case UIO_SYSSPACE:
193: c = *(u_char *) iov->iov_base;
194: break;
195:
196: case UIO_USERISPACE:
197: c = fuibyte(iov->iov_base);
198: break;
199: }
200: if (c < 0)
201: return (-1);
202: iov->iov_base++;
203: iov->iov_len--;
204: uio->uio_resid--;
205: uio->uio_offset++;
206: return (c);
207: }
208: #endif /* notdef */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.