1 /* 2 * catrw.c -- open a file with O_RDWR and print it. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 */ 10 #include <stdio.h> 11 #include <stdlib.h> 12 #include <string.h> 13 #include <fcntl.h> 14 #include <unistd.h> 15 #include <errno.h> 16 17 #define BUFSIZE 4096 18 char buf[BUFSIZE]; 19 catrw(int fd)20void catrw(int fd) { 21 int i; 22 for (;;) { 23 while ( (i = read(fd, buf, BUFSIZE)) < 0 && errno == EINTR) 24 ; 25 if (i <= 0) 26 break; 27 write(1, buf, i); 28 } 29 } 30 main(int argc,char * argv[])31int main(int argc, char *argv[]) { 32 int fd; 33 if (argc == 1) 34 catrw(0); 35 else { 36 while (--argc && (fd = open(*++argv, O_RDWR))) { 37 catrw(fd); 38 close(fd); 39 } 40 } 41 return 0; 42 } 43 44