aboutsummaryrefslogtreecommitdiff
path: root/cat.c
diff options
context:
space:
mode:
Diffstat (limited to 'cat.c')
-rw-r--r--cat.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/cat.c b/cat.c
index 8718c4d02..5c54c4941 100644
--- a/cat.c
+++ b/cat.c
@@ -22,15 +22,27 @@
22#include "internal.h" 22#include "internal.h"
23#include <stdio.h> 23#include <stdio.h>
24 24
25const char cat_usage[] = "[file ...]";
26 25
27extern int cat_more_main(int argc, char **argv) 26static void print_file( FILE *file)
28{ 27{
29 int c; 28 int c;
30 FILE *file = stdin; 29 while ((c = getc(file)) != EOF)
30 putc(c, stdout);
31 fclose(file);
32 fflush(stdout);
33}
34
35extern int cat_more_main(int argc, char **argv)
36{
37 FILE *file;
38
39 if (argc==1) {
40 print_file( stdin);
41 exit( TRUE);
42 }
31 43
32 if ( (argc < 2) || (**(argv+1) == '-') ) { 44 if ( **(argv+1) == '-' ) {
33 fprintf(stderr, "Usage: %s %s", *argv, cat_usage); 45 fprintf(stderr, "Usage: cat [file ...]\n");
34 exit(FALSE); 46 exit(FALSE);
35 } 47 }
36 argc--; 48 argc--;
@@ -42,11 +54,7 @@ extern int cat_more_main(int argc, char **argv)
42 perror(*argv); 54 perror(*argv);
43 exit(FALSE); 55 exit(FALSE);
44 } 56 }
45 while ((c = getc(file)) != EOF) 57 print_file( file);
46 putc(c, stdout);
47 fclose(file);
48 fflush(stdout);
49
50 argc--; 58 argc--;
51 argv++; 59 argv++;
52 } 60 }