- while (tp->t_canq.c_cc > 1 && uio->uio_resid > 0)
- if (ureadc(getc(&tp->t_canq), uio) < 0) {
- error = EFAULT;
+ while (tp->t_canq.c_cc > 1 && uio_resid(uio) > 0) {
+ int cc;
+ char buf[BUFSIZ];
+
+ cc = min(uio_resid(uio), BUFSIZ);
+ // Don't copy the very last byte
+ cc = min(cc, tp->t_canq.c_cc - 1);
+ cc = q_to_b(&tp->t_canq, buf, cc);
+ error = uiomove(buf, cc, uio);
+ if (error)