/[imapfilter]/imapfilter/tty.c
ViewVC logotype

Contents of /imapfilter/tty.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show annotations)
Tue Dec 17 19:17:04 2002 UTC (21 years, 4 months ago) by lefcha
Branch: MAIN
Changes since 1.5: +11 -4 lines
File MIME type: text/plain
Corrected tty functions in case the file descriptor is not a terminal.

1 #include <stdio.h>
2 #include <unistd.h>
3 #include <string.h>
4 #include <errno.h>
5 #include <termios.h>
6
7 #include "config.h"
8 #include "imapfilter.h"
9
10
11 extern unsigned int flags;
12
13 static struct termios otio, ntio; /* Original and new tty settings. */
14
15
16 /*
17 * Store original term attributes.
18 */
19 int tty_store(void)
20 {
21 if (isatty(fileno(stdin)))
22 flags |= FLAG_TTY;
23
24 if (tcgetattr(fileno(stdin), &otio)) {
25 error("imapfilter: getting term attributes; %s\n", strerror(errno));
26 return ERROR_TERMIO;
27 }
28 return 0;
29 }
30
31
32 /*
33 * Disable echo.
34 */
35 int tty_disable_echo(void)
36 {
37 if (!(flags & FLAG_TTY))
38 return 0;
39
40 ntio = otio;
41 ntio.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
42
43 flags |= FLAG_TTY_MODIFIED;
44
45 if (tcsetattr(fileno(stdin), TCSAFLUSH, &ntio)) {
46 error("imapfilter: setting term attributes; %s\n", strerror(errno));
47 return ERROR_TERMIO;
48 }
49 return 0;
50 }
51
52
53 /*
54 * Restore original term attributes.
55 */
56 int tty_restore(void)
57 {
58 if (!(flags & FLAG_TTY) || !(flags & FLAG_TTY_MODIFIED))
59 return 0;
60
61 if (tcsetattr(fileno(stdin), TCSAFLUSH, &otio)) {
62 error("imapfilter: setting term attributes; %s\n", strerror(errno));
63 return ERROR_TERMIO;
64 }
65 flags &= ~(FLAG_TTY_MODIFIED);
66
67 return 0;
68 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26