-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwritevt.c
58 lines (47 loc) · 929 Bytes
/
writevt.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
#include <stdio.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <unistd.h>
char *progname;
static int usage() {
printf("Usage: %s /dev/ttyXY text\n", progname);
return 2;
}
int main(int argc, char **argv) {
int fd, argi;
char *term = NULL;
char *text = NULL;
progname = argv[0];
argi = 1;
if (argi < argc)
term = argv[argi++];
else {
fprintf(stderr, "%s: no tty specified\n", progname);
return usage();
}
if (argi < argc)
text = argv[argi++];
else {
fprintf(stderr, "%s: no text specified\n", progname);
return usage();
}
if (argi != argc) {
fprintf(stderr, "%s: too many arguments\n", progname);
return usage();
}
fd = open(term, O_RDONLY);
if (fd < 0) {
perror(term);
fprintf(stderr, "%s: could not open tty\n", progname);
return 1;
}
while (*text) {
if (ioctl(fd, TIOCSTI, text)) {
perror("ioctl");
return 1;
}
text++;
}
return 0;
}