-/* subr_xxx.c 4.14 82/07/25 */
+/* subr_xxx.c 4.21 82/12/17 */
+
+#include "../machine/pte.h"
#include "../h/param.h"
#include "../h/systm.h"
#include "../h/proc.h"
#include "../h/fs.h"
#include "../h/vm.h"
-#include "../h/pte.h"
#include "../h/cmap.h"
+#include "../h/uio.h"
/*
- * Pass back c to the user at his location u_base;
- * update u_base, u_count, and u_offset. Return -1
- * on the last character of the user's read.
- * u_base is in the user address space unless u_segflg is set.
- */
-passc(c)
-register c;
-{
- register id;
-
- if ((id = u.u_segflg) == 1)
- *u.u_base = c;
- else
- if (id?suibyte(u.u_base, c):subyte(u.u_base, c) < 0) {
- u.u_error = EFAULT;
- return (-1);
- }
- u.u_count--;
- u.u_offset++;
- u.u_base++;
- return (u.u_count == 0? -1: 0);
-}
-
-#include "ct.h"
-#if NCT > 0
-/*
- * Pick up and return the next character from the user's
- * write call at location u_base;
- * update u_base, u_count, and u_offset. Return -1
- * when u_count is exhausted. u_base is in the user's
- * address space unless u_segflg is set.
- */
-cpass()
-{
- register c, id;
-
- if (u.u_count == 0)
- return (-1);
- if ((id = u.u_segflg) == 1)
- c = *u.u_base;
- else
- if ((c = id==0?fubyte(u.u_base):fuibyte(u.u_base)) < 0) {
- u.u_error = EFAULT;
- return (-1);
- }
- u.u_count--;
- u.u_offset++;
- u.u_base++;
- return (c&0377);
-}
-#endif
-
-/*
- * Routine which sets a user error; placed in
- * illegal entries in the bdevsw and cdevsw tables.
+ * Routine placed in illegal entries in the bdevsw and cdevsw tables.
*/
nodev()
{
- u.u_error = ENODEV;
+ return (ENODEV);
}
/*
nulldev()
{
+ return (0);
}
imin(a, b)
unsigned
min(a, b)
- unsigned int a, b;
+ u_int a, b;
{
return (a < b ? a : b);
unsigned
max(a, b)
- unsigned int a, b;
+ u_int a, b;
{
return (a > b ? a : b);
}
-struct proc *
-pfind(pid)
- int pid;
-{
- register struct proc *p;
-
- for (p = &proc[pidhash[PIDHASH(pid)]]; p != &proc[0]; p = &proc[p->p_idhash])
- if (p->p_pid == pid)
- return (p);
- return ((struct proc *)0);
-}
extern cabase, calimit;
extern struct pte camap[];
return (0);
}
-ffs(mask)
- register long mask;
-{
- register int i;
-
- for(i=1; i<NSIG; i++) {
- if (mask & 1)
- return (i);
- mask >>= 1;
- }
- return (0);
-}
-
bcmp(s1, s2, len)
register char *s1, *s2;
register int len;
{
- while (--len)
+ while (len--)
if (*s1++ != *s2++)
return (1);
return (0);
return (len);
}
#endif
+
+/*
+ * Pass back c to the user.
+ */
+passuc(c, uio)
+ register c;
+ struct uio *uio;
+{
+ register struct iovec *iov = uio->uio_iov;
+
+ switch (uio->uio_segflg) {
+
+ case 0:
+ if (subyte(iov->iov_base, c) < 0)
+ goto fault;
+ break;
+
+ case 1:
+ *iov->iov_base = c;
+ break;
+
+ case 2:
+ if (suibyte(iov->iov_base, c) < 0)
+ goto fault;
+ break;
+ }
+ iov->iov_base++;
+ iov->iov_len--;
+ uio->uio_resid--;
+ uio->uio_offset++;
+ if (iov->iov_len <= 0) {
+ uio->uio_iov++;
+ uio->uio_iovcnt--;
+ }
+ return (0);
+fault:
+ return (EFAULT);
+}