1
0
mirror of https://git.savannah.gnu.org/git/coreutils.git synced 2026-11-06 20:44:02 +03:00

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.
This commit is contained in:
Jim Meyering
2000-05-13 06:46:55 +00:00
parent 68c6a5d828
commit 47827e2ec2

View File

@@ -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;