diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-10-26 23:25:17 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-10-26 23:25:17 +0000 |
commit | 467f463615e7329b267abea02da9ed9cedd2382b (patch) | |
tree | f4f2aa58fa669aed6e2c50bb7aa648a79ec1873d | |
parent | 6dc3a21627db11fa0f374afe29a6bbf4f89c8b64 (diff) | |
download | busybox-w32-467f463615e7329b267abea02da9ed9cedd2382b.tar.gz busybox-w32-467f463615e7329b267abea02da9ed9cedd2382b.tar.bz2 busybox-w32-467f463615e7329b267abea02da9ed9cedd2382b.zip |
rename functions to more understandable names
git-svn-id: svn://busybox.net/trunk/busybox@16447 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | archival/dpkg.c | 4 | ||||
-rw-r--r-- | coreutils/cat.c | 4 | ||||
-rw-r--r-- | coreutils/cksum.c | 2 | ||||
-rw-r--r-- | coreutils/cmp.c | 5 | ||||
-rw-r--r-- | coreutils/cut.c | 2 | ||||
-rw-r--r-- | coreutils/fold.c | 4 | ||||
-rw-r--r-- | coreutils/head.c | 4 | ||||
-rw-r--r-- | coreutils/md5_sha1_sum.c | 2 | ||||
-rw-r--r-- | coreutils/sum.c | 6 | ||||
-rw-r--r-- | coreutils/tee.c | 2 | ||||
-rw-r--r-- | coreutils/uudecode.c | 2 | ||||
-rw-r--r-- | coreutils/wc.c | 4 | ||||
-rw-r--r-- | editors/sed.c | 2 | ||||
-rw-r--r-- | findutils/grep.c | 2 | ||||
-rw-r--r-- | include/libbb.h | 32 | ||||
-rw-r--r-- | libbb/Kbuild | 2 | ||||
-rw-r--r-- | libbb/fclose_nonstdin.c | 2 | ||||
-rw-r--r-- | libbb/fgets_str.c | 10 | ||||
-rw-r--r-- | libbb/wfopen.c | 8 | ||||
-rw-r--r-- | libbb/wfopen_input.c | 13 | ||||
-rw-r--r-- | libbb/xfuncs.c | 1 | ||||
-rw-r--r-- | loginutils/deluser.c | 4 | ||||
-rw-r--r-- | miscutils/readahead.c | 2 | ||||
-rw-r--r-- | miscutils/strings.c | 4 | ||||
-rw-r--r-- | shell/lash.c | 4 | ||||
-rw-r--r-- | util-linux/fdisk.c | 2 | ||||
-rw-r--r-- | util-linux/more.c | 2 |
27 files changed, 63 insertions, 68 deletions
diff --git a/archival/dpkg.c b/archival/dpkg.c index 2f7372100..2b9c4b82d 100644 --- a/archival/dpkg.c +++ b/archival/dpkg.c | |||
@@ -787,7 +787,7 @@ static void index_status_file(const char *filename) | |||
787 | unsigned int status_num; | 787 | unsigned int status_num; |
788 | 788 | ||
789 | status_file = xfopen(filename, "r"); | 789 | status_file = xfopen(filename, "r"); |
790 | while ((control_buffer = fgets_str(status_file, "\n\n")) != NULL) { | 790 | while ((control_buffer = xmalloc_fgets_str(status_file, "\n\n")) != NULL) { |
791 | const unsigned int package_num = fill_package_struct(control_buffer); | 791 | const unsigned int package_num = fill_package_struct(control_buffer); |
792 | if (package_num != -1) { | 792 | if (package_num != -1) { |
793 | status_node = xmalloc(sizeof(status_node_t)); | 793 | status_node = xmalloc(sizeof(status_node_t)); |
@@ -842,7 +842,7 @@ static void write_status_file(deb_file_t **deb_file) | |||
842 | int i = 0; | 842 | int i = 0; |
843 | 843 | ||
844 | /* Update previously known packages */ | 844 | /* Update previously known packages */ |
845 | while ((control_buffer = fgets_str(old_status_file, "\n\n")) != NULL) { | 845 | while ((control_buffer = xmalloc_fgets_str(old_status_file, "\n\n")) != NULL) { |
846 | if ((tmp_string = strstr(control_buffer, "Package:")) == NULL) { | 846 | if ((tmp_string = strstr(control_buffer, "Package:")) == NULL) { |
847 | continue; | 847 | continue; |
848 | } | 848 | } |
diff --git a/coreutils/cat.c b/coreutils/cat.c index 10eb29c4d..a95980552 100644 --- a/coreutils/cat.c +++ b/coreutils/cat.c | |||
@@ -26,10 +26,10 @@ int cat_main(int argc, char **argv) | |||
26 | } | 26 | } |
27 | 27 | ||
28 | do { | 28 | do { |
29 | f = bb_wfopen_input(*argv); | 29 | f = fopen_or_warn_stdin(*argv); |
30 | if (f) { | 30 | if (f) { |
31 | off_t r = bb_copyfd_eof(fileno(f), STDOUT_FILENO); | 31 | off_t r = bb_copyfd_eof(fileno(f), STDOUT_FILENO); |
32 | bb_fclose_nonstdin(f); | 32 | fclose_if_not_stdin(f); |
33 | if (r >= 0) { | 33 | if (r >= 0) { |
34 | continue; | 34 | continue; |
35 | } | 35 | } |
diff --git a/coreutils/cksum.c b/coreutils/cksum.c index 3a9b0b08c..52213328c 100644 --- a/coreutils/cksum.c +++ b/coreutils/cksum.c | |||
@@ -22,7 +22,7 @@ int cksum_main(int argc, char **argv) | |||
22 | int inp_stdin = (argc == optind) ? 1 : 0; | 22 | int inp_stdin = (argc == optind) ? 1 : 0; |
23 | 23 | ||
24 | do { | 24 | do { |
25 | fp = bb_wfopen_input((inp_stdin) ? bb_msg_standard_input : *++argv); | 25 | fp = fopen_or_warn_stdin((inp_stdin) ? bb_msg_standard_input : *++argv); |
26 | 26 | ||
27 | crc = 0; | 27 | crc = 0; |
28 | length = 0; | 28 | length = 0; |
diff --git a/coreutils/cmp.c b/coreutils/cmp.c index 2b923c845..71007eac1 100644 --- a/coreutils/cmp.c +++ b/coreutils/cmp.c | |||
@@ -27,10 +27,9 @@ static FILE *cmp_xfopen_input(const char * const filename) | |||
27 | { | 27 | { |
28 | FILE *fp; | 28 | FILE *fp; |
29 | 29 | ||
30 | if ((fp = bb_wfopen_input(filename)) != NULL) { | 30 | fp = fopen_or_warn_stdin(filename); |
31 | if (fp) | ||
31 | return fp; | 32 | return fp; |
32 | } | ||
33 | |||
34 | exit(xfunc_error_retval); /* We already output an error message. */ | 33 | exit(xfunc_error_retval); /* We already output an error message. */ |
35 | } | 34 | } |
36 | 35 | ||
diff --git a/coreutils/cut.c b/coreutils/cut.c index 5dc35434f..a538e3d20 100644 --- a/coreutils/cut.c +++ b/coreutils/cut.c | |||
@@ -272,7 +272,7 @@ int cut_main(int argc, char **argv) | |||
272 | FILE *file; | 272 | FILE *file; |
273 | 273 | ||
274 | for (; optind < argc; optind++) { | 274 | for (; optind < argc; optind++) { |
275 | file = bb_wfopen(argv[optind], "r"); | 275 | file = fopen_or_warn(argv[optind], "r"); |
276 | if (file) { | 276 | if (file) { |
277 | cut_file(file); | 277 | cut_file(file); |
278 | fclose(file); | 278 | fclose(file); |
diff --git a/coreutils/fold.c b/coreutils/fold.c index e33be5594..9ca693dff 100644 --- a/coreutils/fold.c +++ b/coreutils/fold.c | |||
@@ -70,7 +70,7 @@ int fold_main(int argc, char **argv) | |||
70 | } | 70 | } |
71 | 71 | ||
72 | do { | 72 | do { |
73 | FILE *istream = bb_wfopen_input(*argv); | 73 | FILE *istream = fopen_or_warn_stdin(*argv); |
74 | int c; | 74 | int c; |
75 | int column = 0; /* Screen column where next char will go. */ | 75 | int column = 0; /* Screen column where next char will go. */ |
76 | int offset_out = 0; /* Index in `line_out' for next char. */ | 76 | int offset_out = 0; /* Index in `line_out' for next char. */ |
@@ -144,7 +144,7 @@ rescan: | |||
144 | fwrite(line_out, sizeof(char), (size_t) offset_out, stdout); | 144 | fwrite(line_out, sizeof(char), (size_t) offset_out, stdout); |
145 | } | 145 | } |
146 | 146 | ||
147 | if (ferror(istream) || bb_fclose_nonstdin(istream)) { | 147 | if (ferror(istream) || fclose_if_not_stdin(istream)) { |
148 | bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */ | 148 | bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */ |
149 | errs |= EXIT_FAILURE; | 149 | errs |= EXIT_FAILURE; |
150 | } | 150 | } |
diff --git a/coreutils/head.c b/coreutils/head.c index 2e9000df4..d732461f7 100644 --- a/coreutils/head.c +++ b/coreutils/head.c | |||
@@ -112,7 +112,7 @@ int head_main(int argc, char **argv) | |||
112 | #endif | 112 | #endif |
113 | 113 | ||
114 | do { | 114 | do { |
115 | fp = bb_wfopen_input(*argv); | 115 | fp = fopen_or_warn_stdin(*argv); |
116 | if (fp) { | 116 | if (fp) { |
117 | if (fp == stdin) { | 117 | if (fp == stdin) { |
118 | *argv = (char *) bb_msg_standard_input; | 118 | *argv = (char *) bb_msg_standard_input; |
@@ -127,7 +127,7 @@ int head_main(int argc, char **argv) | |||
127 | } | 127 | } |
128 | putchar(c); | 128 | putchar(c); |
129 | } | 129 | } |
130 | if (bb_fclose_nonstdin(fp)) { | 130 | if (fclose_if_not_stdin(fp)) { |
131 | bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */ | 131 | bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */ |
132 | retval = EXIT_FAILURE; | 132 | retval = EXIT_FAILURE; |
133 | } | 133 | } |
diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c index ca23d8ac4..93d894655 100644 --- a/coreutils/md5_sha1_sum.c +++ b/coreutils/md5_sha1_sum.c | |||
@@ -162,7 +162,7 @@ int md5_sha1_sum_main(int argc, char **argv) | |||
162 | bb_error_msg("WARNING: %d of %d computed checksums did NOT match", | 162 | bb_error_msg("WARNING: %d of %d computed checksums did NOT match", |
163 | count_failed, count_total); | 163 | count_failed, count_total); |
164 | } | 164 | } |
165 | if (bb_fclose_nonstdin(pre_computed_stream) == EOF) { | 165 | if (fclose_if_not_stdin(pre_computed_stream) == EOF) { |
166 | bb_perror_msg_and_die("cannot close file %s", file_ptr); | 166 | bb_perror_msg_and_die("cannot close file %s", file_ptr); |
167 | } | 167 | } |
168 | } else { | 168 | } else { |
diff --git a/coreutils/sum.c b/coreutils/sum.c index d663e34dd..93f4e22eb 100644 --- a/coreutils/sum.c +++ b/coreutils/sum.c | |||
@@ -38,7 +38,7 @@ static int bsd_sum_file(const char *file, int print_name) | |||
38 | fp = stdin; | 38 | fp = stdin; |
39 | have_read_stdin++; | 39 | have_read_stdin++; |
40 | } else { | 40 | } else { |
41 | fp = bb_wfopen(file, "r"); | 41 | fp = fopen_or_warn(file, "r"); |
42 | if (fp == NULL) | 42 | if (fp == NULL) |
43 | goto out; | 43 | goto out; |
44 | } | 44 | } |
@@ -52,11 +52,11 @@ static int bsd_sum_file(const char *file, int print_name) | |||
52 | 52 | ||
53 | if (ferror(fp)) { | 53 | if (ferror(fp)) { |
54 | bb_perror_msg(file); | 54 | bb_perror_msg(file); |
55 | bb_fclose_nonstdin(fp); | 55 | fclose_if_not_stdin(fp); |
56 | goto out; | 56 | goto out; |
57 | } | 57 | } |
58 | 58 | ||
59 | if (bb_fclose_nonstdin(fp) == EOF) { | 59 | if (fclose_if_not_stdin(fp) == EOF) { |
60 | bb_perror_msg(file); | 60 | bb_perror_msg(file); |
61 | goto out; | 61 | goto out; |
62 | } | 62 | } |
diff --git a/coreutils/tee.c b/coreutils/tee.c index f0e1fad86..06c94aba6 100644 --- a/coreutils/tee.c +++ b/coreutils/tee.c | |||
@@ -49,7 +49,7 @@ int tee_main(int argc, char **argv) | |||
49 | goto GOT_NEW_FILE; | 49 | goto GOT_NEW_FILE; |
50 | 50 | ||
51 | do { | 51 | do { |
52 | if ((*p = bb_wfopen(*argv, mode)) == NULL) { | 52 | if ((*p = fopen_or_warn(*argv, mode)) == NULL) { |
53 | retval = EXIT_FAILURE; | 53 | retval = EXIT_FAILURE; |
54 | continue; | 54 | continue; |
55 | } | 55 | } |
diff --git a/coreutils/uudecode.c b/coreutils/uudecode.c index c8152a808..a08d985ac 100644 --- a/coreutils/uudecode.c +++ b/coreutils/uudecode.c | |||
@@ -174,7 +174,7 @@ int uudecode_main(int argc, char **argv) | |||
174 | } | 174 | } |
175 | free(line); | 175 | free(line); |
176 | ret = decode_fn_ptr(src_stream, dst_stream); | 176 | ret = decode_fn_ptr(src_stream, dst_stream); |
177 | bb_fclose_nonstdin(src_stream); | 177 | fclose_if_not_stdin(src_stream); |
178 | return(ret); | 178 | return(ret); |
179 | } | 179 | } |
180 | bb_error_msg_and_die("No `begin' line"); | 180 | bb_error_msg_and_die("No `begin' line"); |
diff --git a/coreutils/wc.c b/coreutils/wc.c index ebae5f69f..4b76e5499 100644 --- a/coreutils/wc.c +++ b/coreutils/wc.c | |||
@@ -107,7 +107,7 @@ int wc_main(int argc, char **argv) | |||
107 | 107 | ||
108 | while ((arg = *argv++) != 0) { | 108 | while ((arg = *argv++) != 0) { |
109 | ++num_files; | 109 | ++num_files; |
110 | fp = bb_wfopen_input(arg); | 110 | fp = fopen_or_warn_stdin(arg); |
111 | if (!fp) { | 111 | if (!fp) { |
112 | status = EXIT_FAILURE; | 112 | status = EXIT_FAILURE; |
113 | continue; | 113 | continue; |
@@ -172,7 +172,7 @@ int wc_main(int argc, char **argv) | |||
172 | } | 172 | } |
173 | totals[WC_LENGTH] -= counts[WC_LENGTH]; | 173 | totals[WC_LENGTH] -= counts[WC_LENGTH]; |
174 | 174 | ||
175 | bb_fclose_nonstdin(fp); | 175 | fclose_if_not_stdin(fp); |
176 | 176 | ||
177 | OUTPUT: | 177 | OUTPUT: |
178 | /* coreutils wc tries hard to print pretty columns | 178 | /* coreutils wc tries hard to print pretty columns |
diff --git a/editors/sed.c b/editors/sed.c index 3e33529cb..65ca5606b 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -1194,7 +1194,7 @@ int sed_main(int argc, char **argv) | |||
1194 | process_files(); | 1194 | process_files(); |
1195 | continue; | 1195 | continue; |
1196 | } | 1196 | } |
1197 | file = bb_wfopen(argv[i], "r"); | 1197 | file = fopen_or_warn(argv[i], "r"); |
1198 | if (!file) { | 1198 | if (!file) { |
1199 | status = EXIT_FAILURE; | 1199 | status = EXIT_FAILURE; |
1200 | continue; | 1200 | continue; |
diff --git a/findutils/grep.c b/findutils/grep.c index b7964d1eb..b76a17a41 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
@@ -447,7 +447,7 @@ int grep_main(int argc, char **argv) | |||
447 | } | 447 | } |
448 | } | 448 | } |
449 | matched += grep_file(file); | 449 | matched += grep_file(file); |
450 | bb_fclose_nonstdin(file); | 450 | fclose_if_not_stdin(file); |
451 | grep_done: | 451 | grep_done: |
452 | if (matched < 0) { | 452 | if (matched < 0) { |
453 | /* we found a match but were told to be quiet, stop here and | 453 | /* we found a match but were told to be quiet, stop here and |
diff --git a/include/libbb.h b/include/libbb.h index f435a5915..da936d66e 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -240,20 +240,29 @@ extern void erase_mtab(const char * name); | |||
240 | extern long *find_pid_by_name( const char* pidName); | 240 | extern long *find_pid_by_name( const char* pidName); |
241 | extern long *pidlist_reverse(long *pidList); | 241 | extern long *pidlist_reverse(long *pidList); |
242 | extern char *find_block_device(char *path); | 242 | extern char *find_block_device(char *path); |
243 | extern char *xmalloc_fgets(FILE *file); | ||
244 | /* Chops off '\n' from the end, unlike fgets: */ | ||
245 | extern char *xmalloc_getline(FILE *file); | ||
246 | extern char *bb_get_chunk_from_file(FILE *file, int *end); | ||
247 | extern off_t bb_copyfd_size(int fd1, int fd2, off_t size); | 243 | extern off_t bb_copyfd_size(int fd1, int fd2, off_t size); |
248 | extern off_t bb_copyfd_eof(int fd1, int fd2); | 244 | extern off_t bb_copyfd_eof(int fd1, int fd2); |
249 | extern char bb_process_escape_sequence(const char **ptr); | 245 | extern char bb_process_escape_sequence(const char **ptr); |
250 | extern char *bb_get_last_path_component(char *path); | 246 | extern char *bb_get_last_path_component(char *path); |
251 | extern FILE *bb_wfopen(const char *path, const char *mode); | ||
252 | extern FILE *bb_wfopen_input(const char *filename); | ||
253 | extern FILE *xfopen(const char *path, const char *mode); | ||
254 | 247 | ||
255 | extern int bb_fclose_nonstdin(FILE *f); | 248 | /* Prints to stdout closes entire FILE. Exits on error: */ |
249 | extern void xprint_and_close_file(FILE *file); | ||
250 | extern char *xmalloc_fgets(FILE *file); | ||
251 | /* /* Read up to (and including) TERMINATING_STRING: */ | ||
252 | extern char *xmalloc_fgets_str(FILE *file, const char *terminating_string); | ||
253 | /* Chops off '\n' from the end, unlike fgets: */ | ||
254 | extern char *xmalloc_getline(FILE *file); | ||
255 | extern char *bb_get_chunk_from_file(FILE *file, int *end); | ||
256 | extern void die_if_ferror(FILE *file, const char *msg); | ||
257 | extern void die_if_ferror_stdout(void); | ||
258 | extern void xfflush_stdout(void); | ||
256 | extern void fflush_stdout_and_exit(int retval) ATTRIBUTE_NORETURN; | 259 | extern void fflush_stdout_and_exit(int retval) ATTRIBUTE_NORETURN; |
260 | extern int fclose_if_not_stdin(FILE *file); | ||
261 | extern FILE *xfopen(const char *filename, const char *mode); | ||
262 | /* Prints warning to stderr and returns NULL on failure: */ | ||
263 | extern FILE *fopen_or_warn(const char *filename, const char *mode); | ||
264 | /* "Opens" stdin if filename is special, else just opens file: */ | ||
265 | extern FILE *fopen_or_warn_stdin(const char *filename); | ||
257 | 266 | ||
258 | extern void xstat(char *filename, struct stat *buf); | 267 | extern void xstat(char *filename, struct stat *buf); |
259 | extern int xsocket(int domain, int type, int protocol); | 268 | extern int xsocket(int domain, int type, int protocol); |
@@ -278,10 +287,6 @@ extern const struct option *applet_long_options; | |||
278 | extern uint32_t option_mask32; | 287 | extern uint32_t option_mask32; |
279 | extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...); | 288 | extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...); |
280 | 289 | ||
281 | extern void die_if_ferror(FILE *fp, const char *fn); | ||
282 | extern void die_if_ferror_stdout(void); | ||
283 | extern void xfflush_stdout(void); | ||
284 | |||
285 | extern void bb_warn_ignoring_args(int n); | 290 | extern void bb_warn_ignoring_args(int n); |
286 | 291 | ||
287 | extern void chomp(char *s); | 292 | extern void chomp(char *s); |
@@ -430,8 +435,6 @@ char *concat_path_file(const char *path, const char *filename); | |||
430 | char *concat_subpath_file(const char *path, const char *filename); | 435 | char *concat_subpath_file(const char *path, const char *filename); |
431 | char *last_char_is(const char *s, int c); | 436 | char *last_char_is(const char *s, int c); |
432 | 437 | ||
433 | char *fgets_str(FILE *file, const char *terminating_string); | ||
434 | |||
435 | int execable_file(const char *name); | 438 | int execable_file(const char *name); |
436 | char *find_execable(const char *filename); | 439 | char *find_execable(const char *filename); |
437 | int exists_execable(const char *filename); | 440 | int exists_execable(const char *filename); |
@@ -577,7 +580,6 @@ void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name); | |||
577 | void reset_ino_dev_hashtable(void); | 580 | void reset_ino_dev_hashtable(void); |
578 | 581 | ||
579 | char *xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); | 582 | char *xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); |
580 | void xprint_and_close_file(FILE *file); | ||
581 | 583 | ||
582 | #define FAIL_DELAY 3 | 584 | #define FAIL_DELAY 3 |
583 | extern void bb_do_delay(int seconds); | 585 | extern void bb_do_delay(int seconds); |
diff --git a/libbb/Kbuild b/libbb/Kbuild index 0dd8c2be4..87c09bdfd 100644 --- a/libbb/Kbuild +++ b/libbb/Kbuild | |||
@@ -9,7 +9,7 @@ lib-y:= \ | |||
9 | compare_string_array.o concat_path_file.o copy_file.o copyfd.o \ | 9 | compare_string_array.o concat_path_file.o copy_file.o copyfd.o \ |
10 | crc32.o create_icmp_socket.o create_icmp6_socket.o \ | 10 | crc32.o create_icmp_socket.o create_icmp6_socket.o \ |
11 | device_open.o dump.o error_msg.o error_msg_and_die.o \ | 11 | device_open.o dump.o error_msg.o error_msg_and_die.o \ |
12 | find_pid_by_name.o find_root_device.o fgets_str.o \ | 12 | find_pid_by_name.o find_root_device.o xmalloc_fgets_str.o \ |
13 | full_write.o get_last_path_component.o get_line_from_file.o \ | 13 | full_write.o get_last_path_component.o get_line_from_file.o \ |
14 | herror_msg.o herror_msg_and_die.o \ | 14 | herror_msg.o herror_msg_and_die.o \ |
15 | human_readable.o inet_common.o inode_hash.o isdirectory.o \ | 15 | human_readable.o inet_common.o inode_hash.o isdirectory.o \ |
diff --git a/libbb/fclose_nonstdin.c b/libbb/fclose_nonstdin.c index be986d1b1..951ab30d6 100644 --- a/libbb/fclose_nonstdin.c +++ b/libbb/fclose_nonstdin.c | |||
@@ -15,7 +15,7 @@ | |||
15 | #include <stdio.h> | 15 | #include <stdio.h> |
16 | #include <libbb.h> | 16 | #include <libbb.h> |
17 | 17 | ||
18 | int bb_fclose_nonstdin(FILE *f) | 18 | int fclose_if_not_stdin(FILE *f) |
19 | { | 19 | { |
20 | if (f != stdin) { | 20 | if (f != stdin) { |
21 | return fclose(f); | 21 | return fclose(f); |
diff --git a/libbb/fgets_str.c b/libbb/fgets_str.c index 41370d176..1bc6c3b1c 100644 --- a/libbb/fgets_str.c +++ b/libbb/fgets_str.c | |||
@@ -8,17 +8,12 @@ | |||
8 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 8 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
9 | */ | 9 | */ |
10 | 10 | ||
11 | |||
12 | #include <stdio.h> | ||
13 | #include <stdlib.h> | ||
14 | #include <string.h> | ||
15 | |||
16 | #include "libbb.h" | 11 | #include "libbb.h" |
17 | 12 | ||
18 | /* Read up to (and including) TERMINATING_STRING from FILE and return it. | 13 | /* Read up to (and including) TERMINATING_STRING from FILE and return it. |
19 | * Return NULL on EOF. */ | 14 | * Return NULL on EOF. */ |
20 | 15 | ||
21 | char *fgets_str(FILE *file, const char *terminating_string) | 16 | char *xmalloc_fgets_str(FILE *file, const char *terminating_string) |
22 | { | 17 | { |
23 | char *linebuf = NULL; | 18 | char *linebuf = NULL; |
24 | const int term_length = strlen(terminating_string); | 19 | const int term_length = strlen(terminating_string); |
@@ -36,7 +31,8 @@ char *fgets_str(FILE *file, const char *terminating_string) | |||
36 | 31 | ||
37 | /* grow the line buffer as necessary */ | 32 | /* grow the line buffer as necessary */ |
38 | while (idx > linebufsz - 2) { | 33 | while (idx > linebufsz - 2) { |
39 | linebuf = xrealloc(linebuf, linebufsz += 1000); | 34 | linebufsz += 200; |
35 | linebuf = xrealloc(linebuf, linebufsz); | ||
40 | } | 36 | } |
41 | 37 | ||
42 | linebuf[idx] = ch; | 38 | linebuf[idx] = ch; |
diff --git a/libbb/wfopen.c b/libbb/wfopen.c index 9d663281e..26e6a13e2 100644 --- a/libbb/wfopen.c +++ b/libbb/wfopen.c | |||
@@ -7,14 +7,12 @@ | |||
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <stdio.h> | ||
11 | #include <errno.h> | ||
12 | #include "libbb.h" | 10 | #include "libbb.h" |
13 | 11 | ||
14 | FILE *bb_wfopen(const char *path, const char *mode) | 12 | FILE *fopen_or_warn(const char *path, const char *mode) |
15 | { | 13 | { |
16 | FILE *fp; | 14 | FILE *fp = fopen(path, mode); |
17 | if ((fp = fopen(path, mode)) == NULL) { | 15 | if (!fp) { |
18 | bb_perror_msg("%s", path); | 16 | bb_perror_msg("%s", path); |
19 | errno = 0; | 17 | errno = 0; |
20 | } | 18 | } |
diff --git a/libbb/wfopen_input.c b/libbb/wfopen_input.c index d764f1d06..3da855fe6 100644 --- a/libbb/wfopen_input.c +++ b/libbb/wfopen_input.c | |||
@@ -14,18 +14,17 @@ | |||
14 | * Note: We also consider "" to main stdin (for 'cmp' at least). | 14 | * Note: We also consider "" to main stdin (for 'cmp' at least). |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <stdio.h> | 17 | #include "libbb.h" |
18 | #include <sys/stat.h> | ||
19 | #include <libbb.h> | ||
20 | 18 | ||
21 | FILE *bb_wfopen_input(const char *filename) | 19 | FILE *fopen_or_warn_stdin(const char *filename) |
22 | { | 20 | { |
23 | FILE *fp = stdin; | 21 | FILE *fp = stdin; |
24 | 22 | ||
25 | if ((filename != bb_msg_standard_input) | 23 | if (filename != bb_msg_standard_input |
26 | && filename[0] && ((filename[0] != '-') || filename[1]) | 24 | && filename[0] |
25 | && (filename[0] != '-' || filename[1]) | ||
27 | ) { | 26 | ) { |
28 | fp = bb_wfopen(filename, "r"); | 27 | fp = fopen_or_warn(filename, "r"); |
29 | } | 28 | } |
30 | 29 | ||
31 | return fp; | 30 | return fp; |
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index c5e18c312..1144a67c6 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -341,6 +341,7 @@ char *xasprintf(const char *format, ...) | |||
341 | // close that file. | 341 | // close that file. |
342 | void xprint_and_close_file(FILE *file) | 342 | void xprint_and_close_file(FILE *file) |
343 | { | 343 | { |
344 | fflush(stdout); | ||
344 | // copyfd outputs error messages for us. | 345 | // copyfd outputs error messages for us. |
345 | if (bb_copyfd_eof(fileno(file), 1) == -1) | 346 | if (bb_copyfd_eof(fileno(file), 1) == -1) |
346 | exit(xfunc_error_retval); | 347 | exit(xfunc_error_retval); |
diff --git a/loginutils/deluser.c b/loginutils/deluser.c index bbbd77dbd..795dae49f 100644 --- a/loginutils/deluser.c +++ b/loginutils/deluser.c | |||
@@ -54,7 +54,7 @@ static void del_line_matching(const char *login, const char *filename) | |||
54 | struct stat statbuf; | 54 | struct stat statbuf; |
55 | 55 | ||
56 | 56 | ||
57 | if ((passwd = bb_wfopen(filename, "r"))) { | 57 | if ((passwd = fopen_or_warn(filename, "r"))) { |
58 | // Remove pointless const. | 58 | // Remove pointless const. |
59 | xstat((char *)filename, &statbuf); | 59 | xstat((char *)filename, &statbuf); |
60 | buffer = (char *) xmalloc(statbuf.st_size * sizeof(char)); | 60 | buffer = (char *) xmalloc(statbuf.st_size * sizeof(char)); |
@@ -64,7 +64,7 @@ static void del_line_matching(const char *login, const char *filename) | |||
64 | b = boundary(buffer, login); | 64 | b = boundary(buffer, login); |
65 | if (b.stop != 0) { | 65 | if (b.stop != 0) { |
66 | /* write the file w/o the user */ | 66 | /* write the file w/o the user */ |
67 | if ((passwd = bb_wfopen(filename, "w"))) { | 67 | if ((passwd = fopen_or_warn(filename, "w"))) { |
68 | fwrite(buffer, (b.start - 1), sizeof(char), passwd); | 68 | fwrite(buffer, (b.start - 1), sizeof(char), passwd); |
69 | fwrite(&buffer[b.stop], (statbuf.st_size - b.stop), sizeof(char), passwd); | 69 | fwrite(&buffer[b.stop], (statbuf.st_size - b.stop), sizeof(char), passwd); |
70 | fclose(passwd); | 70 | fclose(passwd); |
diff --git a/miscutils/readahead.c b/miscutils/readahead.c index 49cd7fd09..356c40451 100644 --- a/miscutils/readahead.c +++ b/miscutils/readahead.c | |||
@@ -20,7 +20,7 @@ int readahead_main(int argc, char **argv) | |||
20 | if (argc == 1) bb_show_usage(); | 20 | if (argc == 1) bb_show_usage(); |
21 | 21 | ||
22 | while (*++argv) { | 22 | while (*++argv) { |
23 | if ((f = bb_wfopen(*argv, "r")) != NULL) { | 23 | if ((f = fopen_or_warn(*argv, "r")) != NULL) { |
24 | int r, fd=fileno(f); | 24 | int r, fd=fileno(f); |
25 | 25 | ||
26 | r = readahead(fd, 0, fdlength(fd)); | 26 | r = readahead(fd, 0, fdlength(fd)); |
diff --git a/miscutils/strings.c b/miscutils/strings.c index dae17315e..0d5576e9b 100644 --- a/miscutils/strings.c +++ b/miscutils/strings.c | |||
@@ -45,7 +45,7 @@ int strings_main(int argc, char **argv) | |||
45 | } | 45 | } |
46 | 46 | ||
47 | do { | 47 | do { |
48 | file = bb_wfopen(*argv, "r"); | 48 | file = fopen_or_warn(*argv, "r"); |
49 | if (file) { | 49 | if (file) { |
50 | PIPE: | 50 | PIPE: |
51 | count = 0; | 51 | count = 0; |
@@ -75,7 +75,7 @@ PIPE: | |||
75 | } | 75 | } |
76 | count++; | 76 | count++; |
77 | } while (c != EOF); | 77 | } while (c != EOF); |
78 | bb_fclose_nonstdin(file); | 78 | fclose_if_not_stdin(file); |
79 | } else { | 79 | } else { |
80 | status = EXIT_FAILURE; | 80 | status = EXIT_FAILURE; |
81 | } | 81 | } |
diff --git a/shell/lash.c b/shell/lash.c index 96c0b3007..4067bc6bc 100644 --- a/shell/lash.c +++ b/shell/lash.c | |||
@@ -426,7 +426,7 @@ static int builtin_source(struct child_prog *child) | |||
426 | FILE *input; | 426 | FILE *input; |
427 | int status; | 427 | int status; |
428 | 428 | ||
429 | input = bb_wfopen(child->argv[1], "r"); | 429 | input = fopen_or_warn(child->argv[1], "r"); |
430 | if (!input) { | 430 | if (!input) { |
431 | return EXIT_FAILURE; | 431 | return EXIT_FAILURE; |
432 | } | 432 | } |
@@ -1522,7 +1522,7 @@ int lash_main(int argc_l, char **argv_l) | |||
1522 | llist_add_to(&close_me_list, (void *)(long)fileno(prof_input)); | 1522 | llist_add_to(&close_me_list, (void *)(long)fileno(prof_input)); |
1523 | /* Now run the file */ | 1523 | /* Now run the file */ |
1524 | busy_loop(prof_input); | 1524 | busy_loop(prof_input); |
1525 | bb_fclose_nonstdin(prof_input); | 1525 | fclose_if_not_stdin(prof_input); |
1526 | llist_pop(&close_me_list); | 1526 | llist_pop(&close_me_list); |
1527 | } | 1527 | } |
1528 | } | 1528 | } |
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index 40a8d1bae..6e4bf6418 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c | |||
@@ -2771,7 +2771,7 @@ tryprocpt(void) | |||
2771 | char line[100], ptname[100], devname[120], *s; | 2771 | char line[100], ptname[100], devname[120], *s; |
2772 | int ma, mi, sz; | 2772 | int ma, mi, sz; |
2773 | 2773 | ||
2774 | procpt = bb_wfopen("/proc/partitions", "r"); | 2774 | procpt = fopen_or_warn("/proc/partitions", "r"); |
2775 | 2775 | ||
2776 | while (fgets(line, sizeof(line), procpt)) { | 2776 | while (fgets(line, sizeof(line), procpt)) { |
2777 | if (sscanf(line, " %d %d %d %[^\n ]", | 2777 | if (sscanf(line, " %d %d %d %[^\n ]", |
diff --git a/util-linux/more.c b/util-linux/more.c index f68292e80..85209ce61 100644 --- a/util-linux/more.c +++ b/util-linux/more.c | |||
@@ -81,7 +81,7 @@ int more_main(int argc, char **argv) | |||
81 | if (argc == 0) { | 81 | if (argc == 0) { |
82 | file = stdin; | 82 | file = stdin; |
83 | } else | 83 | } else |
84 | file = bb_wfopen(*argv, "r"); | 84 | file = fopen_or_warn(*argv, "r"); |
85 | if(file==0) | 85 | if(file==0) |
86 | goto loop; | 86 | goto loop; |
87 | 87 | ||