aboutsummaryrefslogtreecommitdiff
path: root/rin.c
blob: 72463d821264226b24e4446131ad7e86561f27e6 (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
#include <err.h>
#include <fcntl.h>
#include <signal.h>
#include <termios.h>
#include <unistd.h>

int
main()
{
	int c, n, o, t;
	struct termios orig, term;

	t = 0;

	if((o = open("/var/tmp/r.in", O_RDWR)) == -1)
		err(1, "/var/tmp/r.in");

        /* Enter "raw" terminal mode. */
        tcgetattr(t, &orig);
        tcgetattr(t, &term);
        term.c_lflag &= ~(ICANON|ECHO|ISIG);
        tcsetattr(t, TCSANOW, &term);

	while((n = read(t, &c, 1)) > 0){
		if(c == 26) /* ^Z */
			break;
		if(c != '\n')
			write(t, &c, 1);
		write(o, &c, 1);
	}

	/* Restore original terminal mode. */
	tcsetattr(t, TCSANOW, &orig);
}