aboutsummaryrefslogtreecommitdiffstats
path: root/catrw.c
blob: 164d2a376f02330c0f63d5aeb11328cf078823bd (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
/*
 *  catrw.c  --  open a file with O_RDWR and print it.
 * 
 *  This file is placed in the public domain.
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>

#define BUFSIZE 4096
char buf[BUFSIZE];

void catrw(int fd) {
    int i;
    for (;;) {
	while ( (i = read(fd, buf, BUFSIZE)) < 0 && errno == EINTR)
	    ;
	if (i <= 0)
	    break;
	write(1, buf, i);
    }
}

int main(int argc, char *argv[]) {
    int fd;
    if (argc == 1)
	catrw(0);
    else {
	while (--argc && (fd = open(*++argv, O_RDWR))) {
	    catrw(fd);
	    close(fd);
	}
    }
    return 0;
}