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