summaryrefslogtreecommitdiff
path: root/src/du.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2005-07-03 06:25:42 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2005-07-03 06:25:42 +0000
commit6af6438b0a0ffc4d4b92e81a70d29557cc573309 (patch)
tree3fdf5662a25e7712643119280d4bbcb43fc78769 /src/du.c
parent42f845ebc79ab8337bb182550c56f915a2ce8303 (diff)
downloadcoreutils-6af6438b0a0ffc4d4b92e81a70d29557cc573309.tar.xz
(main): Reuse stdin rather than opening a new stream.
This saves a file descriptor.
Diffstat (limited to 'src/du.c')
-rw-r--r--src/du.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/src/du.c b/src/du.c
index 2d2dad222..8ea4ed335 100644
--- a/src/du.c
+++ b/src/du.c
@@ -941,8 +941,6 @@ main (int argc, char **argv)
if (files_from)
{
- FILE *istream;
-
/* When using --files0-from=F, you may not specify any files
on the command-line. */
if (optind < argc)
@@ -953,14 +951,13 @@ main (int argc, char **argv)
usage (EXIT_FAILURE);
}
- istream = (STREQ (files_from, "-") ? stdin : fopen (files_from, "r"));
- if (istream == NULL)
+ if (! (STREQ (files_from, "-") || freopen (files_from, "r", stdin)))
error (EXIT_FAILURE, errno, _("cannot open %s for reading"),
quote (files_from));
readtokens0_init (&tok);
- if (! readtokens0 (istream, &tok) || fclose (istream) != 0)
+ if (! readtokens0 (stdin, &tok) || fclose (stdin) != 0)
error (EXIT_FAILURE, 0, _("cannot read file names from %s"),
quote (files_from));