(main): Reuse stdin rather than opening a new stream.
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 3 Jul 2005 06:25:42 +0000 (06:25 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 3 Jul 2005 06:25:42 +0000 (06:25 +0000)
This saves a file descriptor.

src/du.c

index 2d2dad2..8ea4ed3 100644 (file)
--- 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));