|
|
1.1 root 1:
2: #include <err.h>
3: #include <fcntl.h>
4: #include <sys/ioctl.h>
5: #include <stdio.h>
6: #include <termios.h>
7: #include <unistd.h>
8:
9: int
10: main(int ac, char *av[])
11: {
12:
13: int fd;
14:
15: fd = open("/dev/dty00", O_RDWR);
16: if (fd < 0) {
17: err(1, "open");
18: }
19:
20: ioctl(fd, TIOCNXCL);
21:
22: termios t;
23: tcgetattr(fd, &t);
24: fprintf(stderr, "c_iflag=%08x\n", t.c_iflag);
25: fprintf(stderr, "c_oflag=%08x\n", t.c_oflag);
26: fprintf(stderr, "c_cflag=%08x\n", t.c_cflag);
27: fprintf(stderr, "c_lflag=%08x\n", t.c_lflag);
28: cfmakeraw(&t);
29: cfsetspeed(&t, B9600);
30: t.c_iflag = IGNBRK;
31: t.c_cflag = CREAD | CS8 | CLOCAL;
32: t.c_lflag &= ~ICANON;
33: t.c_cc[VTIME] = 0;
34: t.c_cc[VMIN] = 1;
35: tcsetattr(fd, TCSANOW, &t);
36: tcgetattr(fd, &t);
37: fprintf(stderr, "\nc_iflag=%08x\n", t.c_iflag);
38: fprintf(stderr, "c_oflag=%08x\n", t.c_oflag);
39: fprintf(stderr, "c_cflag=%08x\n", t.c_cflag);
40: fprintf(stderr, "c_lflag=%08x\n", t.c_lflag);
41:
42: for (;;) {
43: char buf[4];
44: int r;
45:
46: int c = getchar();
47:
48: buf[0] = c;
49: r = write(fd, buf, 1);
50: if (r <= 0) {
51: err(1, "write");
52: }
53: r = read(fd, buf, 1);
54: fprintf(stderr, "%d ", r);
55: if (r < 0) {
56: err(1, "read");
57: }
58: if (r > 0) {
59: putchar(buf[0]);
60: }
61: }
62: return 0;
63: }
64:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.