summaryrefslogtreecommitdiff
path: root/src/sort.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-05-20 22:03:12 +0000
committerJim Meyering <jim@meyering.net>2000-05-20 22:03:12 +0000
commit02f78789286f150562ff4ab9692f4b7021d60088 (patch)
treedc56e145e79152a2a169e192201adce50a8c34d5 /src/sort.c
parenta311f0eac5727c158d586e0e95bd647fe15328ef (diff)
downloadcoreutils-02f78789286f150562ff4ab9692f4b7021d60088.tar.xz
Arrange to call close_stdout upon exit. Don't close stdout explicitly.
(but set exit status and file name, too)
Diffstat (limited to 'src/sort.c')
-rw-r--r--src/sort.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/sort.c b/src/sort.c
index acd564202..0ae7c9938 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <assert.h>
#include "system.h"
+#include "closeout.h"
#include "long-options.h"
#include "error.h"
#include "hard-locale.h"
@@ -1854,6 +1855,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ close_stdout_set_status (SORT_FAILURE);
+ atexit (close_stdout);
+
#ifdef ENABLE_NLS
hard_LC_COLLATE = hard_locale (LC_COLLATE);
@@ -2123,6 +2127,7 @@ but lacks following character offset"));
else
outfile = argv[++i];
}
+ close_stdout_set_file_name (outfile);
goto outer;
case 's':
stable = 1;
@@ -2221,6 +2226,7 @@ but lacks following character offset"));
struct stat outstat;
if (stat (outfile, &outstat) == 0)
{
+ /* FIXME: warn about this */
/* The following code prevents a race condition when
people use the brain dead shell programming idiom:
cat file | sort -o file
@@ -2317,8 +2323,6 @@ but lacks following character offset"));
if (have_read_stdin && fclose (stdin) == EOF)
error (SORT_FAILURE, errno, "%s", outfile);
- if (ferror (stdout) || fclose (stdout) == EOF)
- error (SORT_FAILURE, errno, _("%s: write error"), outfile);
exit (EXIT_SUCCESS);
}