xref: /original-bsd/usr.bin/window/wwtty.c (revision ad93c43e)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12 
13 #ifndef lint
14 static char sccsid[] = "@(#)wwtty.c	3.11 (Berkeley) 02/21/88";
15 #endif /* not lint */
16 
17 #include "ww.h"
18 #include <fcntl.h>
19 
20 wwgettty(d, t)
21 register struct ww_tty *t;
22 {
23 	if (ioctl(d, TIOCGETP, (char *)&t->ww_sgttyb) < 0)
24 		goto bad;
25 	if (ioctl(d, TIOCGETC, (char *)&t->ww_tchars) < 0)
26 		goto bad;
27 	if (ioctl(d, TIOCGLTC, (char *)&t->ww_ltchars) < 0)
28 		goto bad;
29 	if (ioctl(d, TIOCLGET, (char *)&t->ww_lmode) < 0)
30 		goto bad;
31 	if (ioctl(d, TIOCGETD, (char *)&t->ww_ldisc) < 0)
32 		goto bad;
33 	if ((t->ww_fflags = fcntl(d, F_GETFL, 0)) < 0)
34 		goto bad;
35 	return 0;
36 bad:
37 	wwerrno = WWE_SYS;
38 	return -1;
39 }
40 
41 /*
42  * Set the modes of tty 'd' to 't'
43  * 'o' is the current modes.  We set the line discipline only if
44  * it changes, to avoid unnecessary flushing of typeahead.
45  */
46 wwsettty(d, t, o)
47 register struct ww_tty *t, *o;
48 {
49 	if (ioctl(d, TIOCSETN, (char *)&t->ww_sgttyb) < 0)
50 		goto bad;
51 	if (ioctl(d, TIOCSETC, (char *)&t->ww_tchars) < 0)
52 		goto bad;
53 	if (ioctl(d, TIOCSLTC, (char *)&t->ww_ltchars) < 0)
54 		goto bad;
55 	if (ioctl(d, TIOCLSET, (char *)&t->ww_lmode) < 0)
56 		goto bad;
57 	if ((o == 0 || t->ww_ldisc != o->ww_ldisc) &&
58 	    ioctl(d, TIOCSETD, (char *)&t->ww_ldisc) < 0)
59 		goto bad;
60 	if (fcntl(d, F_SETFL, t->ww_fflags) < 0)
61 		goto bad;
62 	return 0;
63 bad:
64 	wwerrno = WWE_SYS;
65 	return -1;
66 }
67