summaryrefslogtreecommitdiff
path: root/util/term.c
blob: a9861d592db147864b10a493a4de89b08415e798 (plain)
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
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include <fcntl.h>
#include <errno.h>
#include <unistd.h>

#include "tty.h"

void usage(char *p) {
    fprintf(stderr, "Usage: %s <tty>\n", p);
    exit(1);
}

int main(int argc, char *argv[]) {
    int tty_fd;

    if (argc != 2) {
        usage(argv[0]);
    }

    tty_fd = tty_open(argv[1]);
    if (tty_fd < 0) {
        fprintf(stderr, "ERROR %i: %s\n", errno, strerror(errno));
        return 1;
    }

    while (1) {
        char buf[256];
        int rv;

        rv = read(tty_fd, buf, sizeof(buf));
        if (rv < 0) continue;

        write(STDOUT_FILENO, buf, rv);
        fflush(stdout);
    }
}