uuprog
diff cat.c @ 0:4f628556fa3e
uuprog initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 25 Aug 2011 08:53:01 +0300 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/cat.c Thu Aug 25 08:53:01 2011 +0300 1.3 @@ -0,0 +1,23 @@ 1.4 +/*! cc -o cat cat.c */ 1.5 +#include <stdio.h> 1.6 +#include <string.h> 1.7 +#include <errno.h> 1.8 + 1.9 +int main(int argc, char **argv) 1.10 +{ 1.11 + char buf[4096]; 1.12 + size_t rbytes; 1.13 + FILE *fp; 1.14 + 1.15 + while(*++argv) { 1.16 + if(!(fp = fopen(*argv, "rb"))) { 1.17 + fprintf(stderr, "cat: %s: %s\n", *argv, strerror(errno)); 1.18 + } else { 1.19 + while((rbytes = fread(buf, 1, sizeof buf, fp)) > 0) { 1.20 + fwrite(buf, 1, rbytes, stdout); 1.21 + } 1.22 + fclose(fp); 1.23 + } 1.24 + } 1.25 + return 0; 1.26 +}