From: Eric S. Raymond Date: Tue, 16 Sep 2003 03:40:57 +0000 (+0000) Subject: Don't open the output file until we have to. X-Git-Tag: 2.0~58 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=a1c7a2f424b534b4a4df8799f49958e74a16da3d;p=comparator.git Don't open the output file until we have to. --- diff --git a/main.c b/main.c index 3a4d2e2..a22fde8 100644 --- 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);