uuprog

view 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 source
1 /*! cc -o cat cat.c */
2 #include <stdio.h>
3 #include <string.h>
4 #include <errno.h>
6 int main(int argc, char **argv)
7 {
8 char buf[4096];
9 size_t rbytes;
10 FILE *fp;
12 while(*++argv) {
13 if(!(fp = fopen(*argv, "rb"))) {
14 fprintf(stderr, "cat: %s: %s\n", *argv, strerror(errno));
15 } else {
16 while((rbytes = fread(buf, 1, sizeof buf, fp)) > 0) {
17 fwrite(buf, 1, rbytes, stdout);
18 }
19 fclose(fp);
20 }
21 }
22 return 0;
23 }