Annotation of src/usr.bin/bc/tty.c, Revision 1.5
1.5 ! guenther 1: /* $OpenBSD: tty.c,v 1.4 2017/07/02 23:19:07 deraadt Exp $ */
1.1 otto 2:
3: /*
4: * Copyright (c) 2013, Otto Moerbeek <otto@drijf.net>
5: *
6: * Permission to use, copy, modify, and distribute this software for any
7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
9: *
10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17: */
18:
19: #include <errno.h>
20: #include <signal.h>
21: #include <histedit.h>
22: #include <termios.h>
23: #include "extern.h"
24:
25: struct termios ttysaved, ttyedit;
26:
1.2 deraadt 27: static int
1.1 otto 28: settty(struct termios *t)
29: {
30: int ret;
31:
1.3 jsg 32: while ((ret = tcsetattr(0, TCSADRAIN, t)) == -1 && errno == EINTR)
1.1 otto 33: continue;
34: return ret;
35: }
36:
37: int
38: gettty(struct termios *t)
39: {
40: int ret;
41:
1.3 jsg 42: while ((ret = tcgetattr(0, t)) == -1 && errno == EINTR)
1.1 otto 43: continue;
44: return ret;
45: }
46:
47: void
48: tstpcont(int sig)
49: {
50: int save_errno = errno;
51:
52: if (sig == SIGTSTP) {
53: signal(SIGCONT, tstpcont);
54: gettty(&ttyedit);
1.4 deraadt 55: settty(&ttysaved);
1.1 otto 56: } else {
57: signal(SIGTSTP, tstpcont);
1.4 deraadt 58: settty(&ttyedit);
1.1 otto 59: }
60: signal(sig, SIG_DFL);
61: kill(0, sig);
62: errno = save_errno;
63: }