aboutsummaryrefslogtreecommitdiff
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 1b4928e1f..a7c1c32f5 100644
--- a/libbb/wfopen_input.c
+++ b/libbb/wfopen_input.c
@@ -10,8 +10,6 @@
10/* A number of applets need to open a file for reading, where the filename 10/* A number of applets need to open a file for reading, where the filename
11 * is a command line arg. Since often that arg is '-' (meaning stdin), 11 * is a command line arg. Since often that arg is '-' (meaning stdin),
12 * we avoid testing everywhere by consolidating things in this routine. 12 * we avoid testing everywhere by consolidating things in this routine.
13 *
14 * Note: we also consider "" to mean stdin (for 'cmp' at least).
15 */ 13 */
16 14
17#include "libbb.h" 15#include "libbb.h"
@@ -21,11 +19,30 @@ FILE *fopen_or_warn_stdin(const char *filename)
21 FILE *fp = stdin; 19 FILE *fp = stdin;
22 20
23 if (filename != bb_msg_standard_input 21 if (filename != bb_msg_standard_input
24 && filename[0]
25 && NOT_LONE_DASH(filename) 22 && NOT_LONE_DASH(filename)
26 ) { 23 ) {
27 fp = fopen_or_warn(filename, "r"); 24 fp = fopen_or_warn(filename, "r");
28 } 25 }
29
30 return fp; 26 return fp;
31} 27}
28
29FILE *xfopen_stdin(const char *filename)
30{
31 FILE *fp = fopen_or_warn_stdin(filename);
32 if (fp)
33 return fp;
34 xfunc_die(); /* We already output an error message. */
35}
36
37int open_or_warn_stdin(const char *filename)
38{
39 int fd = STDIN_FILENO;
40
41 if (filename != bb_msg_standard_input
42 && NOT_LONE_DASH(filename)
43 ) {
44 fd = open_or_warn(filename, O_RDONLY);
45 }
46
47 return fd;
48}