-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_termios.c
81 lines (76 loc) · 1.02 KB
/
test_termios.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ioctl.h>
int main(int argc, char *argv[])
{
int fd;
if (argc < 3)
{
printf("test_termios <tty file> <cmd>\n");
return -1;
}
fd = open(argv[1], O_RDWR);
if (fd < 0)
{
perror("open");
return -1;
}
char *cmd = argv[2];
if (!strcmp(cmd, "flush"))
{
if (tcflush(fd, TCIOFLUSH) < 0)
{
perror("tcflush");
}
}
else
if (!strcmp(cmd, "insert"))
{
if (ioctl(fd, TIOCSTI, "\r") < 0)
{
perror("ioctl");
}
}
else
if (!strcmp(cmd, "restart"))
{
if (tcflush(fd, TCOON) < 0)
{
perror("tcflush");
}
}
else
if (!strcmp(cmd, "suspend"))
{
if (tcflush(fd, TCOOFF) < 0)
{
perror("tcflush");
}
}
else
if (!strcmp(cmd, "stop"))
{
if (tcflow(fd, TCIOFF) < 0)
{
perror("tcflow");
}
}
else
if (!strcmp(cmd, "stop"))
{
if (tcflow(fd, TCION) < 0)
{
perror("tcflow");
}
}
else
{
printf("Invalid cmd\n");
}
close(fd);
return 0;
}