diff options
Diffstat (limited to 'libbb')
-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 |
6 files changed, 15 insertions, 21 deletions
diff --git a/libbb/Kbuild b/libbb/Kbuild index 0dd8c2be4..87c09bdfd 100644 --- a/libbb/Kbuild +++ b/libbb/Kbuild @@ -9,7 +9,7 @@ lib-y:= \ compare_string_array.o concat_path_file.o copy_file.o copyfd.o \ crc32.o create_icmp_socket.o create_icmp6_socket.o \ device_open.o dump.o error_msg.o error_msg_and_die.o \ - find_pid_by_name.o find_root_device.o fgets_str.o \ + find_pid_by_name.o find_root_device.o xmalloc_fgets_str.o \ full_write.o get_last_path_component.o get_line_from_file.o \ herror_msg.o herror_msg_and_die.o \ 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 @@ #include <stdio.h> #include <libbb.h> -int bb_fclose_nonstdin(FILE *f) +int fclose_if_not_stdin(FILE *f) { if (f != stdin) { 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 @@ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - #include "libbb.h" /* Read up to (and including) TERMINATING_STRING from FILE and return it. * Return NULL on EOF. */ -char *fgets_str(FILE *file, const char *terminating_string) +char *xmalloc_fgets_str(FILE *file, const char *terminating_string) { char *linebuf = NULL; const int term_length = strlen(terminating_string); @@ -36,7 +31,8 @@ char *fgets_str(FILE *file, const char *terminating_string) /* grow the line buffer as necessary */ while (idx > linebufsz - 2) { - linebuf = xrealloc(linebuf, linebufsz += 1000); + linebufsz += 200; + linebuf = xrealloc(linebuf, linebufsz); } 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 @@ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ -#include <stdio.h> -#include <errno.h> #include "libbb.h" -FILE *bb_wfopen(const char *path, const char *mode) +FILE *fopen_or_warn(const char *path, const char *mode) { - FILE *fp; - if ((fp = fopen(path, mode)) == NULL) { + FILE *fp = fopen(path, mode); + if (!fp) { bb_perror_msg("%s", path); errno = 0; } 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 @@ * Note: We also consider "" to main stdin (for 'cmp' at least). */ -#include <stdio.h> -#include <sys/stat.h> -#include <libbb.h> +#include "libbb.h" -FILE *bb_wfopen_input(const char *filename) +FILE *fopen_or_warn_stdin(const char *filename) { FILE *fp = stdin; - if ((filename != bb_msg_standard_input) - && filename[0] && ((filename[0] != '-') || filename[1]) + if (filename != bb_msg_standard_input + && filename[0] + && (filename[0] != '-' || filename[1]) ) { - fp = bb_wfopen(filename, "r"); + fp = fopen_or_warn(filename, "r"); } 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, ...) // close that file. void xprint_and_close_file(FILE *file) { + fflush(stdout); // copyfd outputs error messages for us. if (bb_copyfd_eof(fileno(file), 1) == -1) exit(xfunc_error_retval); |