cat

C89 implementation of cat
git clone git://ssnf.xyz/cat
Log | Files | Refs

cat.c (358B)


      1 #include <stdio.h>
      2 
      3 int
      4 main(int argc, char* argv[])
      5 {
      6 	char buf[4096];
      7 	FILE* f;
      8 	int i, n;
      9 
     10 	for (i = 1; i < argc; ++i) {
     11 		if (argv[i][0] == '-' && argv[i][1] == '\0')
     12 			f = stdin;
     13 		else {
     14 			f = fopen(argv[i], "r");
     15 			if (!f) {
     16 				perror(argv[i]);
     17 				return 1;
     18 			}
     19 		}
     20 		while (n = fread(buf, 1, sizeof(buf), f))
     21 			fwrite(buf, 1, n, stdout);
     22 	}
     23 }