diff options
author | Jim Meyering <jim@meyering.net> | 2000-05-20 22:06:38 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2000-05-20 22:06:38 +0000 |
commit | 24f2bd8c9f62409ef7d7c919c9a53f438ee991cb (patch) | |
tree | 0d30aa82a2c6c12ab2224c5ecffb9ded6a11caaa /src/uniq.c | |
parent | ac8180336348bee878584b013d71f84e5d047f21 (diff) | |
download | coreutils-24f2bd8c9f62409ef7d7c919c9a53f438ee991cb.tar.xz |
Arrange to call close_stdout upon exit. Don't close stdout explicitly.
Diffstat (limited to 'src/uniq.c')
-rw-r--r-- | src/uniq.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/uniq.c b/src/uniq.c index 3639d9315..fa0fa0e5f 100644 --- a/src/uniq.c +++ b/src/uniq.c @@ -1,5 +1,5 @@ /* uniq -- remove duplicate lines from a sorted file - Copyright (C) 86, 91, 1995-1998, 1999 Free Software Foundation, Inc. + Copyright (C) 86, 91, 1995-1998, 1999, 2000 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,6 +24,7 @@ #include <sys/types.h> #include "system.h" +#include "closeout.h" #include "linebuffer.h" #include "error.h" #include "xstrtol.h" @@ -313,7 +314,9 @@ check_file (const char *infile, const char *outfile) if (ferror (istream) || fclose (istream) == EOF) error (EXIT_FAILURE, errno, _("error reading %s"), infile); - if (ferror (ostream) || fclose (ostream) == EOF) + /* Close ostream only if it's not stdout -- the latter is closed + via the atexit-invoked close_stdout. */ + if (ostream != stdout && (ferror (ostream) || fclose (ostream) == EOF)) error (EXIT_FAILURE, errno, _("error writing %s"), outfile); free (lb1.buffer); @@ -331,6 +334,8 @@ main (int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); + atexit (close_stdout); + skip_chars = 0; skip_fields = 0; check_chars = 0; |