updated readme, fix configuration shell invoked twice.
[lunaix-os.git] / lunaix-os / usr / testp.c
1 #include <errno.h>
2 #include <fcntl.h>
3 #include <sys/wait.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include <unistd.h>
7
8 void
9 test_serial(char* dev, int wr)
10 {
11     int fd = open(dev, FO_WRONLY);
12     if (fd < 0) {
13         printf("tty %s not accessable (%d)\n", dev, errno);
14         return;
15     }
16
17     int sz = 0;
18     char buf[256];
19
20     if (!wr) {
21         printf("tty input: ");
22
23         if ((sz = read(fd, buf, 31)) < 0) {
24             printf("read to tty failed (%d)\n", errno);
25         }
26
27         buf[sz] = 0;
28
29         printf("%s", buf);
30     }
31     else {
32         int size = snprintf(buf, 256, "serial test: %s", dev);
33         write(fd, buf, size);
34     }
35
36     close(fd);
37 }
38
39 int
40 main(int argc, char* argv[])
41 {
42     if (argc != 2) {
43         printf("usage: testp path_to_dev\n");
44         return 1;
45     }
46
47     char* target = argv[1];
48
49     test_serial(target, 1);
50
51     return 0;
52 }