diff options
Diffstat (limited to 'coreutils/cat.c')
-rw-r--r-- | coreutils/cat.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/coreutils/cat.c b/coreutils/cat.c index 8718c4d..5c54c49 100644 --- a/coreutils/cat.c +++ b/coreutils/cat.c @@ -22,15 +22,27 @@ #include "internal.h" #include <stdio.h> -const char cat_usage[] = "[file ...]"; -extern int cat_more_main(int argc, char **argv) +static void print_file( FILE *file) { int c; - FILE *file = stdin; + while ((c = getc(file)) != EOF) + putc(c, stdout); + fclose(file); + fflush(stdout); +} + +extern int cat_more_main(int argc, char **argv) +{ + FILE *file; + + if (argc==1) { + print_file( stdin); + exit( TRUE); + } - if ( (argc < 2) || (**(argv+1) == '-') ) { - fprintf(stderr, "Usage: %s %s", *argv, cat_usage); + if ( **(argv+1) == '-' ) { + fprintf(stderr, "Usage: cat [file ...]\n"); exit(FALSE); } argc--; @@ -42,11 +54,7 @@ extern int cat_more_main(int argc, char **argv) perror(*argv); exit(FALSE); } - while ((c = getc(file)) != EOF) - putc(c, stdout); - fclose(file); - fflush(stdout); - + print_file( file); argc--; argv++; } |