cat.c (745B)
1 /* See LICENSE file for copyright and license details. */ 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <unistd.h> 5 6 #include "text.h" 7 #include "util.h" 8 9 static void 10 usage(void) 11 { 12 eprintf("usage: %s [-u] [file...]\n", argv0); 13 } 14 15 int 16 main(int argc, char *argv[]) 17 { 18 FILE *fp; 19 int ret = 0; 20 21 ARGBEGIN { 22 case 'u': 23 setbuf(stdout, NULL); 24 break; 25 default: 26 usage(); 27 } ARGEND; 28 29 if (argc == 0) { 30 concat(stdin, "<stdin>", stdout, "<stdout>"); 31 } else { 32 for (; argc; argc--, argv++) { 33 if (argv[0][0] == '-' && !argv[0][1]) 34 argv[0] = "/dev/fd/0"; 35 if (!(fp = fopen(argv[0], "r"))) { 36 weprintf("fopen %s:", argv[0]); 37 ret = 1; 38 continue; 39 } 40 concat(fp, argv[0], stdout, "<stdout>"); 41 fclose(fp); 42 } 43 } 44 return ret; 45 }