Commit | Line | Data |
---|---|---|
60de5df9 | 1 | /* |
46e9ea25 KB |
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 | |
5e8b0e60 KB |
6 | * provided that the above copyright notice and this paragraph are |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
60de5df9 EW |
16 | */ |
17 | ||
46e9ea25 | 18 | #ifndef lint |
5e8b0e60 | 19 | static char sccsid[] = "@(#)wwtty.c 3.12 (Berkeley) %G%"; |
46e9ea25 KB |
20 | #endif /* not lint */ |
21 | ||
b94626a3 | 22 | #include "ww.h" |
b1189050 | 23 | #include <fcntl.h> |
b94626a3 EW |
24 | |
25 | wwgettty(d, t) | |
26 | register struct ww_tty *t; | |
27 | { | |
20029082 | 28 | if (ioctl(d, TIOCGETP, (char *)&t->ww_sgttyb) < 0) |
03e75950 | 29 | goto bad; |
20029082 | 30 | if (ioctl(d, TIOCGETC, (char *)&t->ww_tchars) < 0) |
03e75950 | 31 | goto bad; |
20029082 | 32 | if (ioctl(d, TIOCGLTC, (char *)&t->ww_ltchars) < 0) |
03e75950 | 33 | goto bad; |
20029082 | 34 | if (ioctl(d, TIOCLGET, (char *)&t->ww_lmode) < 0) |
03e75950 | 35 | goto bad; |
20029082 | 36 | if (ioctl(d, TIOCGETD, (char *)&t->ww_ldisc) < 0) |
03e75950 | 37 | goto bad; |
b1189050 EW |
38 | if ((t->ww_fflags = fcntl(d, F_GETFL, 0)) < 0) |
39 | goto bad; | |
b94626a3 | 40 | return 0; |
03e75950 EW |
41 | bad: |
42 | wwerrno = WWE_SYS; | |
43 | return -1; | |
b94626a3 EW |
44 | } |
45 | ||
4cbd8755 EW |
46 | /* |
47 | * Set the modes of tty 'd' to 't' | |
48 | * 'o' is the current modes. We set the line discipline only if | |
49 | * it changes, to avoid unnecessary flushing of typeahead. | |
50 | */ | |
51 | wwsettty(d, t, o) | |
52 | register struct ww_tty *t, *o; | |
b94626a3 | 53 | { |
20029082 | 54 | if (ioctl(d, TIOCSETN, (char *)&t->ww_sgttyb) < 0) |
03e75950 | 55 | goto bad; |
20029082 | 56 | if (ioctl(d, TIOCSETC, (char *)&t->ww_tchars) < 0) |
03e75950 | 57 | goto bad; |
20029082 | 58 | if (ioctl(d, TIOCSLTC, (char *)&t->ww_ltchars) < 0) |
03e75950 | 59 | goto bad; |
20029082 | 60 | if (ioctl(d, TIOCLSET, (char *)&t->ww_lmode) < 0) |
03e75950 | 61 | goto bad; |
4cbd8755 | 62 | if ((o == 0 || t->ww_ldisc != o->ww_ldisc) && |
20029082 | 63 | ioctl(d, TIOCSETD, (char *)&t->ww_ldisc) < 0) |
03e75950 | 64 | goto bad; |
b1189050 EW |
65 | if (fcntl(d, F_SETFL, t->ww_fflags) < 0) |
66 | goto bad; | |
b94626a3 | 67 | return 0; |
03e75950 EW |
68 | bad: |
69 | wwerrno = WWE_SYS; | |
70 | return -1; | |
b94626a3 | 71 | } |