Commit | Line | Data |
---|---|---|
da7c5cc6 | 1 | /* |
8429d022 | 2 | * Copyright (c) 1982, 1986, 1991 Regents of the University of California. |
6a8af092 | 3 | * All rights reserved. |
da7c5cc6 | 4 | * |
8429d022 MK |
5 | * %sccs.include.redist.c% |
6 | * | |
6a8af092 | 7 | * @(#)kern_subr.c 7.8 (Berkeley) %G% |
da7c5cc6 | 8 | */ |
358708a6 | 9 | |
94368568 JB |
10 | #include "param.h" |
11 | #include "systm.h" | |
c49c0c2b | 12 | #include "proc.h" |
358708a6 | 13 | |
c4ec2128 | 14 | uiomove(cp, n, uio) |
358708a6 SL |
15 | register caddr_t cp; |
16 | register int n; | |
358708a6 SL |
17 | register struct uio *uio; |
18 | { | |
19 | register struct iovec *iov; | |
20 | u_int cnt; | |
21 | int error = 0; | |
22 | ||
c49c0c2b | 23 | #ifdef DIAGNOSTIC |
c4ec2128 KM |
24 | if (uio->uio_rw != UIO_READ && uio->uio_rw != UIO_WRITE) |
25 | panic("uiomove: mode"); | |
c49c0c2b KM |
26 | if (uio->uio_segflg == UIO_USERSPACE && uio->uio_procp != curproc) |
27 | panic("uiomove proc"); | |
28 | #endif | |
358708a6 SL |
29 | while (n > 0 && uio->uio_resid) { |
30 | iov = uio->uio_iov; | |
31 | cnt = iov->iov_len; | |
32 | if (cnt == 0) { | |
33 | uio->uio_iov++; | |
34 | uio->uio_iovcnt--; | |
35 | continue; | |
36 | } | |
37 | if (cnt > n) | |
38 | cnt = n; | |
39 | switch (uio->uio_segflg) { | |
40 | ||
c41770c0 KM |
41 | case UIO_USERSPACE: |
42 | case UIO_USERISPACE: | |
c4ec2128 | 43 | if (uio->uio_rw == UIO_READ) |
358708a6 SL |
44 | error = copyout(cp, iov->iov_base, cnt); |
45 | else | |
46 | error = copyin(iov->iov_base, cp, cnt); | |
47 | if (error) | |
48 | return (error); | |
49 | break; | |
50 | ||
c41770c0 | 51 | case UIO_SYSSPACE: |
c4ec2128 | 52 | if (uio->uio_rw == UIO_READ) |
358708a6 SL |
53 | bcopy((caddr_t)cp, iov->iov_base, cnt); |
54 | else | |
55 | bcopy(iov->iov_base, (caddr_t)cp, cnt); | |
56 | break; | |
57 | } | |
58 | iov->iov_base += cnt; | |
59 | iov->iov_len -= cnt; | |
60 | uio->uio_resid -= cnt; | |
61 | uio->uio_offset += cnt; | |
62 | cp += cnt; | |
63 | n -= cnt; | |
64 | } | |
65 | return (error); | |
66 | } | |
67 | ||
68 | /* | |
69 | * Give next character to user as result of read. | |
70 | */ | |
71 | ureadc(c, uio) | |
72 | register int c; | |
73 | register struct uio *uio; | |
74 | { | |
75 | register struct iovec *iov; | |
76 | ||
77 | again: | |
78 | if (uio->uio_iovcnt == 0) | |
79 | panic("ureadc"); | |
80 | iov = uio->uio_iov; | |
81 | if (iov->iov_len <= 0 || uio->uio_resid <= 0) { | |
82 | uio->uio_iovcnt--; | |
83 | uio->uio_iov++; | |
84 | goto again; | |
85 | } | |
86 | switch (uio->uio_segflg) { | |
87 | ||
c41770c0 | 88 | case UIO_USERSPACE: |
358708a6 SL |
89 | if (subyte(iov->iov_base, c) < 0) |
90 | return (EFAULT); | |
91 | break; | |
92 | ||
c41770c0 | 93 | case UIO_SYSSPACE: |
358708a6 SL |
94 | *iov->iov_base = c; |
95 | break; | |
96 | ||
c41770c0 | 97 | case UIO_USERISPACE: |
358708a6 SL |
98 | if (suibyte(iov->iov_base, c) < 0) |
99 | return (EFAULT); | |
100 | break; | |
101 | } | |
102 | iov->iov_base++; | |
103 | iov->iov_len--; | |
104 | uio->uio_resid--; | |
105 | uio->uio_offset++; | |
106 | return (0); | |
107 | } | |
108 | ||
514c3fd2 MT |
109 | strcat(src, append) |
110 | register char *src, *append; | |
111 | { | |
112 | ||
113 | for (; *src; ++src) | |
6a8af092 | 114 | continue; |
514c3fd2 | 115 | while (*src++ = *append++) |
6a8af092 | 116 | continue; |
514c3fd2 MT |
117 | } |
118 | ||
119 | strcpy(to, from) | |
120 | register char *to, *from; | |
121 | { | |
122 | ||
6a8af092 CT |
123 | for (; *to = *from; ++from, ++to) |
124 | continue; | |
514c3fd2 MT |
125 | } |
126 | ||
127 | strncpy(to, from, cnt) | |
128 | register char *to, *from; | |
129 | register int cnt; | |
130 | { | |
131 | ||
132 | for (; cnt && (*to = *from); --cnt, ++from, ++to) | |
6a8af092 | 133 | continue; |
514c3fd2 MT |
134 | *to = '\0'; |
135 | } | |
136 | ||
6a8af092 | 137 | #ifdef vax /* unused except by ct.c, other oddities XXX */ |
358708a6 SL |
138 | /* |
139 | * Get next character written in by user from uio. | |
140 | */ | |
141 | uwritec(uio) | |
142 | struct uio *uio; | |
143 | { | |
144 | register struct iovec *iov; | |
145 | register int c; | |
146 | ||
9b428195 MK |
147 | if (uio->uio_resid <= 0) |
148 | return (-1); | |
358708a6 | 149 | again: |
9b428195 | 150 | if (uio->uio_iovcnt <= 0) |
358708a6 SL |
151 | panic("uwritec"); |
152 | iov = uio->uio_iov; | |
153 | if (iov->iov_len == 0) { | |
358708a6 | 154 | uio->uio_iov++; |
9b428195 MK |
155 | if (--uio->uio_iovcnt == 0) |
156 | return (-1); | |
358708a6 SL |
157 | goto again; |
158 | } | |
159 | switch (uio->uio_segflg) { | |
160 | ||
c41770c0 | 161 | case UIO_USERSPACE: |
358708a6 SL |
162 | c = fubyte(iov->iov_base); |
163 | break; | |
164 | ||
c41770c0 | 165 | case UIO_SYSSPACE: |
8429d022 | 166 | c = *(u_char *) iov->iov_base; |
358708a6 SL |
167 | break; |
168 | ||
c41770c0 | 169 | case UIO_USERISPACE: |
358708a6 SL |
170 | c = fuibyte(iov->iov_base); |
171 | break; | |
172 | } | |
173 | if (c < 0) | |
174 | return (-1); | |
175 | iov->iov_base++; | |
176 | iov->iov_len--; | |
177 | uio->uio_resid--; | |
178 | uio->uio_offset++; | |
8429d022 | 179 | return (c); |
358708a6 | 180 | } |
6a8af092 | 181 | #endif /* vax */ |