summaryrefslogtreecommitdiff
path: root/coreutils/cat.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/cat.c')
-rw-r--r--coreutils/cat.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/coreutils/cat.c b/coreutils/cat.c
index eb141dc79..ed3f33650 100644
--- a/coreutils/cat.c
+++ b/coreutils/cat.c
@@ -19,18 +19,21 @@ int bb_cat(char **argv)
19{ 19{
20 static const char *const argv_dash[] = { "-", NULL }; 20 static const char *const argv_dash[] = { "-", NULL };
21 21
22 FILE *f; 22 int fd;
23 int retval = EXIT_SUCCESS; 23 int retval = EXIT_SUCCESS;
24 24
25 if (!*argv) 25 if (!*argv)
26 argv = (char**) &argv_dash; 26 argv = (char**) &argv_dash;
27 27
28 do { 28 do {
29 f = fopen_or_warn_stdin(*argv); 29 fd = STDIN_FILENO;
30 if (f) { 30 if (!LONE_DASH(*argv))
31 fd = open_or_warn(*argv, O_RDONLY);
32 if (fd >= 0) {
31 /* This is not an xfunc - never exits */ 33 /* This is not an xfunc - never exits */
32 off_t r = bb_copyfd_eof(fileno(f), STDOUT_FILENO); 34 off_t r = bb_copyfd_eof(fd, STDOUT_FILENO);
33 fclose_if_not_stdin(f); 35 if (fd != STDIN_FILENO)
36 close(fd);
34 if (r >= 0) 37 if (r >= 0)
35 continue; 38 continue;
36 } 39 }