diff options
author | Manuel Novoa III <mjn3@codepoet.org> | 2003-03-19 09:13:01 +0000 |
---|---|---|
committer | Manuel Novoa III <mjn3@codepoet.org> | 2003-03-19 09:13:01 +0000 |
commit | cad5364599eb5062d59e0c397ed638ddd61a8d5d (patch) | |
tree | a318d0f03aa076c74b576ea45dc543a5669e8e91 /libbb/print_file.c | |
parent | e01f9662a5bd5d91be4f6b3941b57fff73cd5af1 (diff) | |
download | busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.gz busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.bz2 busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.zip |
Major coreutils update.
Diffstat (limited to 'libbb/print_file.c')
-rw-r--r-- | libbb/print_file.c | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/libbb/print_file.c b/libbb/print_file.c index cdd60e7a0..8417c10d3 100644 --- a/libbb/print_file.c +++ b/libbb/print_file.c | |||
@@ -21,39 +21,50 @@ | |||
21 | 21 | ||
22 | #include <stdio.h> | 22 | #include <stdio.h> |
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include <sys/stat.h> | ||
25 | #include "libbb.h" | 24 | #include "libbb.h" |
26 | 25 | ||
27 | 26 | extern void bb_xprint_and_close_file(FILE *file) | |
28 | extern void print_file(FILE *file) | ||
29 | { | 27 | { |
30 | fflush(stdout); | 28 | bb_xfflush_stdout(); |
31 | if (copyfd(fileno(file), fileno(stdout), 0) == -1) { | 29 | /* Note: Do not use STDOUT_FILENO here, as this is a lib routine |
32 | exit(EXIT_FAILURE); | 30 | * and the calling code may have reassigned stdout. */ |
31 | if (bb_copyfd(fileno(file), fileno(stdout), 0) == -1) { | ||
32 | /* bb_copyfd outputs any needed messages, so just die. */ | ||
33 | exit(bb_default_error_retval); | ||
33 | } | 34 | } |
35 | /* Note: Since we're reading, don't bother checking the return value | ||
36 | * of fclose(). The only possible failure is EINTR which | ||
37 | * should already have been taken care of. */ | ||
34 | fclose(file); | 38 | fclose(file); |
35 | } | 39 | } |
36 | 40 | ||
37 | extern int print_file_by_name(char *filename) | 41 | /* Returns: |
42 | * 0 if successful | ||
43 | * -1 if 'filename' does not exist or is a directory | ||
44 | * exits with default error code if an error occurs | ||
45 | */ | ||
46 | |||
47 | extern int bb_xprint_file_by_name(const char *filename) | ||
38 | { | 48 | { |
49 | FILE *f; | ||
50 | |||
51 | #if 0 | ||
52 | /* This check shouldn't be necessary for linux, but is left | ||
53 | * here disabled just in case. */ | ||
39 | struct stat statBuf; | 54 | struct stat statBuf; |
40 | int status = TRUE; | ||
41 | 55 | ||
42 | if(is_directory(filename, TRUE, &statBuf)==TRUE) { | 56 | if(is_directory(filename, TRUE, &statBuf)) { |
43 | error_msg("%s: Is directory", filename); | 57 | bb_error_msg("%s: Is directory", filename); |
44 | status = FALSE; | 58 | } else |
45 | } else { | 59 | #endif |
46 | FILE *f = wfopen(filename, "r"); | 60 | if ((f = bb_wfopen(filename, "r")) != NULL) { |
47 | if(f!=NULL) | 61 | bb_xprint_and_close_file(f); |
48 | print_file(f); | 62 | return 0; |
49 | else | ||
50 | status = FALSE; | ||
51 | } | 63 | } |
52 | 64 | ||
53 | return status; | 65 | return -1; |
54 | } | 66 | } |
55 | 67 | ||
56 | |||
57 | /* END CODE */ | 68 | /* END CODE */ |
58 | /* | 69 | /* |
59 | Local Variables: | 70 | Local Variables: |