diff options
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/fclose_nonstdin.c | 10 | ||||
-rw-r--r-- | libbb/getopt32.c | 2 | ||||
-rw-r--r-- | libbb/wfopen_input.c | 25 |
3 files changed, 29 insertions, 8 deletions
diff --git a/libbb/fclose_nonstdin.c b/libbb/fclose_nonstdin.c index 88e8474f2..768ee946d 100644 --- a/libbb/fclose_nonstdin.c +++ b/libbb/fclose_nonstdin.c @@ -16,8 +16,10 @@ int fclose_if_not_stdin(FILE *f) { - if (f != stdin) { - return fclose(f); - } - return 0; + /* Some more paranoid applets want ferror() check too */ + int r = ferror(f); /* NB: does NOT set errno! */ + if (r) errno = EIO; /* so we'll help it */ + if (f != stdin) + return (r | fclose(f)); /* fclose does set errno on error */ + return r; } diff --git a/libbb/getopt32.c b/libbb/getopt32.c index f48ccaa6a..9e53dfd08 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c @@ -281,6 +281,8 @@ Special characters: /* Code here assumes that 'unsigned' is at least 32 bits wide */ +const char *const bb_argv_dash[] = { "-", NULL }; + const char *opt_complementary; enum { diff --git a/libbb/wfopen_input.c b/libbb/wfopen_input.c index 1b4928e1f..a7c1c32f5 100644 --- a/libbb/wfopen_input.c +++ b/libbb/wfopen_input.c @@ -10,8 +10,6 @@ /* A number of applets need to open a file for reading, where the filename * is a command line arg. Since often that arg is '-' (meaning stdin), * we avoid testing everywhere by consolidating things in this routine. - * - * Note: we also consider "" to mean stdin (for 'cmp' at least). */ #include "libbb.h" @@ -21,11 +19,30 @@ FILE *fopen_or_warn_stdin(const char *filename) FILE *fp = stdin; if (filename != bb_msg_standard_input - && filename[0] && NOT_LONE_DASH(filename) ) { fp = fopen_or_warn(filename, "r"); } - return fp; } + +FILE *xfopen_stdin(const char *filename) +{ + FILE *fp = fopen_or_warn_stdin(filename); + if (fp) + return fp; + xfunc_die(); /* We already output an error message. */ +} + +int open_or_warn_stdin(const char *filename) +{ + int fd = STDIN_FILENO; + + if (filename != bb_msg_standard_input + && NOT_LONE_DASH(filename) + ) { + fd = open_or_warn(filename, O_RDONLY); + } + + return fd; +} |