- if (ioctl(d, TIOCSETP, &t->ww_sgttyb) < 0)
- return -1;
- if (ioctl(d, TIOCSETC, &t->ww_tchars) < 0)
- return -1;
- if (ioctl(d, TIOCSLTC, &t->ww_ltchars) < 0)
+#ifdef OLD_TTY
+ int i;
+
+ /* XXX, for buggy tty drivers that don't wait for output to drain */
+ while (ioctl(d, TIOCOUTQ, &i) >= 0 && i > 0)
+ usleep(100000);
+ if (ioctl(d, TIOCSETN, (char *)&t->ww_sgttyb) < 0)
+ goto bad;
+ if (ioctl(d, TIOCSETC, (char *)&t->ww_tchars) < 0)
+ goto bad;
+ if (ioctl(d, TIOCSLTC, (char *)&t->ww_ltchars) < 0)
+ goto bad;
+ if (ioctl(d, TIOCLSET, (char *)&t->ww_lmode) < 0)
+ goto bad;
+ if (ioctl(d, TIOCGETD, (char *)&i) < 0)
+ goto bad;
+ if (t->ww_ldisc != i &&
+ ioctl(d, TIOCSETD, (char *)&t->ww_ldisc) < 0)
+ goto bad;
+#else
+#ifdef sun
+ /* XXX, for buggy tty drivers that don't wait for output to drain */
+ (void) tcdrain(d);
+#endif
+ if (tcsetattr(d, TCSADRAIN, &t->ww_termios) < 0)
+ goto bad;
+#endif
+ if (fcntl(d, F_SETFL, t->ww_fflags) < 0)
+ goto bad;
+ return 0;
+bad:
+ wwerrno = WWE_SYS;
+ return -1;
+}
+
+/*
+ * The ttysize and stop-start routines must also work
+ * on the control side of pseudoterminals.
+ */
+
+wwgetttysize(d, r, c)
+ int *r, *c;
+{
+ struct winsize winsize;
+
+ if (ioctl(d, TIOCGWINSZ, (char *)&winsize) < 0) {
+ wwerrno = WWE_SYS;