Blob
1 #include <string.h>2 #include <stdio.h>3 #include <err.h>5 static void cat (FILE* file) {6 int ch;7 while ((ch = fgetc(file)) != EOF)8 putchar(ch);9 }11 int main (int argc, char* argv[]) {12 FILE *file;13 int ec = 0;14 int ch;16 if (argc == 1) {17 cat (stdin);18 return 0;19 }21 for (int i = 1; i < argc; ++i) {22 if (strcmp (argv[i], "-") == 0) {23 file = stdin;24 } else {25 file = fopen (argv[i], "r");26 }28 if (file == NULL) {29 warn ("%s", argv[i]);30 ec = 1;31 continue;32 }34 cat (file);36 if (file != stdin)37 fclose (file);38 }39 return ec;40 }