summaryrefslogtreecommitdiff
path: root/libbb/wfopen_input.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/wfopen_input.c')
-rw-r--r--libbb/wfopen_input.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/libbb/wfopen_input.c b/libbb/wfopen_input.c
index 1b4928e..a7c1c32 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;
+}