aboutsummaryrefslogtreecommitdiff
path: root/cat.c
diff options
context:
space:
mode:
Diffstat (limited to 'cat.c')
-rw-r--r--cat.c16
1 files changed, 1 insertions, 15 deletions
diff --git a/cat.c b/cat.c
index c27f07e82..6a9204fe7 100644
--- a/cat.c
+++ b/cat.c
@@ -24,20 +24,8 @@
24#include "internal.h" 24#include "internal.h"
25#include <stdio.h> 25#include <stdio.h>
26 26
27static void print_file(FILE * file)
28{
29 int c;
30
31 while ((c = getc(file)) != EOF)
32 putc(c, stdout);
33 fclose(file);
34 fflush(stdout);
35}
36
37extern int cat_main(int argc, char **argv) 27extern int cat_main(int argc, char **argv)
38{ 28{
39 FILE *file;
40
41 if (argc == 1) { 29 if (argc == 1) {
42 print_file(stdin); 30 print_file(stdin);
43 exit(TRUE); 31 exit(TRUE);
@@ -47,12 +35,10 @@ extern int cat_main(int argc, char **argv)
47 usage(cat_usage); 35 usage(cat_usage);
48 36
49 while (--argc > 0) { 37 while (--argc > 0) {
50 file = fopen(*++argv, "r"); 38 if (print_file_by_name(*++argv) == FALSE) {
51 if (file == NULL) {
52 perror(*argv); 39 perror(*argv);
53 exit(FALSE); 40 exit(FALSE);
54 } 41 }
55 print_file(file);
56 } 42 }
57 return(TRUE); 43 return(TRUE);
58} 44}