diff options
author | Steve Slaven <bpk@hoopajoo.net> | 2019-11-05 06:26:14 (GMT) |
---|---|---|
committer | Steve Slaven <bpk@hoopajoo.net> | 2019-11-05 06:26:14 (GMT) |
commit | 9c4c0a1e366b9d932e4ab2ce03a0e80126d93d9b (patch) | |
tree | 928e4c6f49ac50f7e69777b00073df37d7d11e3f /src/catrw.c | |
parent | eb9898c7fcc017a35c240c1bd83c8a8ff451431a (diff) | |
download | powwow-9c4c0a1e366b9d932e4ab2ce03a0e80126d93d9b.zip powwow-9c4c0a1e366b9d932e4ab2ce03a0e80126d93d9b.tar.gz powwow-9c4c0a1e366b9d932e4ab2ce03a0e80126d93d9b.tar.bz2 |
reorganizing files
Diffstat (limited to 'src/catrw.c')
-rw-r--r-- | src/catrw.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/catrw.c b/src/catrw.c new file mode 100644 index 0000000..40d06e3 --- /dev/null +++ b/src/catrw.c @@ -0,0 +1,43 @@ +/* + * catrw.c -- open a file with O_RDWR and print it. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + */ +#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; +} + |