summaryrefslogtreecommitdiff
path: root/src/dd.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-05-13 06:46:55 +0000
committerJim Meyering <jim@meyering.net>2000-05-13 06:46:55 +0000
commit47827e2ec298a2d9ab0fb5b367654bb14f080921 (patch)
treec5cfa54ccf61155aa0de1e74807e4aa22f713cdb /src/dd.c
parent68c6a5d828b2fa758fcc850854b9bbe0e47e877f (diff)
downloadcoreutils-47827e2ec298a2d9ab0fb5b367654bb14f080921.tar.xz
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.
Diffstat (limited to 'src/dd.c')
-rw-r--r--src/dd.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/dd.c b/src/dd.c
index 752da10f0..a05657281 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -30,6 +30,7 @@
#include <getopt.h>
#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 <bug-fileutils@gnu.org>."));
- 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;