]> thyrsus.com Git - comparator.git/commitdiff
Don't open the output file until we have to.
authorEric S. Raymond <esr@thyrsus.com>
Tue, 16 Sep 2003 03:40:57 +0000 (03:40 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Tue, 16 Sep 2003 03:40:57 +0000 (03:40 +0000)
main.c

diff --git a/main.c b/main.c
index 3a4d2e21b24bb3d4c08c4ee45d1ebbe50de1190e..a22fde89dd4b9a2794484ad604992a2d68a2c94a 100644 (file)
--- a/main.c
+++ b/main.c
@@ -370,6 +370,21 @@ void report_time(char *legend, ...)
     mark_time = endtime;
 }
 
+static FILE *redirect(const char *outfile)
+/* reditrect output to specified file */
+{
+    if (outfile)
+    {
+       if (freopen(outfile, "w", stdout) == NULL)
+       {
+           perror("comparator");
+           exit(1);
+       }
+    }
+
+    return(stdout);
+}
+
 static void usage(void)
 {
     fprintf(stderr,"usage: comparator [-c] [-C] [-d dir ] [-r] [-o file] [-s shredsize] [-v] [-w] [-x] path...\n");
@@ -455,15 +470,6 @@ main(int argc, char *argv[])
 
     report_time(NULL);
 
-    if (outfile)
-    {
-       if (freopen(outfile, "w", stdout) == NULL)
-       {
-           perror("comparator");
-           exit(1);
-       }
-    }
-
     /* special case if user gave exactly one tree */
     if (!compile_only && argcount == 1)
     {
@@ -474,7 +480,7 @@ main(int argc, char *argv[])
            olddir = getcwd(NULL, 0);   /* may fail off Linux */
            chdir(dir);
        }
-       write_scf(argv[optind], stdout);
+       write_scf(argv[optind], redirect(outfile));
        exit(0);
     }
 
@@ -586,6 +592,7 @@ main(int argc, char *argv[])
        dump_array("Consolidated hash list:\n", sort_buffer, sort_count);
 
     /* now we're ready to emit the report */
+    redirect(outfile);
     puts("#SCF-B 2.0");
     printf("Hash-Method: %s\n", scflist->hash_method);
     puts("Merge-Program: comparator " VERSION);