-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathttyraw.c
49 lines (42 loc) · 1.15 KB
/
ttyraw.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
quIRC - simple terminal-based IRC client
Copyright (C) 2010-13 Edward Cree
See quirc.c for license information
ttyraw: set/unset raw mode on tty
Based on http://docs.linux.cz/programming/c/unix_examples/raw.html
*/
#include "ttyraw.h"
struct termios oldtermios;
int ttyraw(int fd)
{
/* Set terminal mode as follows:
Noncanonical mode - turn off ICANON.
Disable signal generation - turn off ISIG
Turn ECHO mode off.
Disable input parity detection (INPCK).
Disable stripping of eighth bit on input (ISTRIP).
Disable flow control (IXON).
Use eight bit characters (CS8).
Disable parity checking (PARENB).
One byte at a time input (MIN=1, TIME=0).
*/
struct termios newtermios;
if(tcgetattr(fd, &oldtermios) < 0)
return(-1);
newtermios = oldtermios;
newtermios.c_lflag &= ~(ICANON | ISIG | ECHO);
newtermios.c_iflag &= ~(INPCK | ISTRIP | IXON);
newtermios.c_cflag &= ~(CSIZE | PARENB);
newtermios.c_cflag |= CS8;
newtermios.c_cc[VMIN] = 1;
newtermios.c_cc[VTIME] = 0;
if(tcsetattr(fd, TCSAFLUSH, &newtermios) < 0)
return(-1);
return(0);
}
int ttyreset(int fd)
{
if(tcsetattr(fd, TCSAFLUSH, &oldtermios) < 0)
return(-1);
return(0);
}