From: Jim Meyering Date: Sat, 13 May 2000 06:46:55 +0000 (+0000) Subject: Include closeout.h. X-Git-Tag: FILEUTILS-4_0s~55 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=47827e2ec298a2d9ab0fb5b367654bb14f080921;p=thirdparty%2Fcoreutils.git Include closeout.h. (usage): Don't call close_stdout here. (close_stdout_wrapper): New, kludgey, function and file-scoped global. (main): Register it with atexit. --- diff --git a/src/dd.c b/src/dd.c index 752da10f06..a05657281b 100644 --- a/src/dd.c +++ b/src/dd.c @@ -30,6 +30,7 @@ #include #include "system.h" +#include "closeout.h" #include "error.h" #include "getpagesize.h" #include "human.h" @@ -314,7 +315,6 @@ Each KEYWORD may be:\n\ sync pad every input block with NULs to ibs-size\n\ ")); puts (_("\nReport bugs to .")); - close_stdout (); } exit (status); } @@ -1048,6 +1048,17 @@ dd_copy (void) return exit_status; } +/* This is gross, but necessary, because of the way close_stdout + works and because dd.c closes STDOUT_FILENO directly. */ +static void (*closeout_func) (void) = close_stdout; + +static void +close_stdout_wrapper (void) +{ + if (*closeout_func) + (*closeout_func) (); +} + int main (int argc, char **argv) { @@ -1059,9 +1070,15 @@ main (int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); + /* Arrange to close stdout if parse_long_options exits. */ + atexit (close_stdout_wrapper); + parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION, AUTHORS, usage); + /* Don't close stdout on exit from here on. */ + closeout_func = NULL; + /* Initialize translation table to identity translation. */ for (i = 0; i < 256; i++) trans_table[i] = i;