summaryrefslogtreecommitdiff
path: root/src/sort.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1994-12-02 16:49:47 +0000
committerJim Meyering <jim@meyering.net>1994-12-02 16:49:47 +0000
commit97f9755aeb35b61ce0b431226077d4b504e98f10 (patch)
treeb74ad021fa87b8b84cf0fdcd0b6fd86445d1485f /src/sort.c
parentf2fc6e9054c6caa4cf10026e9b4a896d97dddd41 (diff)
downloadcoreutils-97f9755aeb35b61ce0b431226077d4b504e98f10.tar.xz
(xfclose): Report failed fflush. Otherwise, failed write to stdout
could be missed because of subsequent clearerr. (main): Include filename in a couple error messages. Add missing %s in an error format string.
Diffstat (limited to 'src/sort.c')
-rw-r--r--src/sort.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/sort.c b/src/sort.c
index 0b93c54be..d86ae4bf8 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -263,7 +263,13 @@ static void
xfclose (fp)
FILE *fp;
{
- fflush (fp);
+ if (fflush (fp) != 0)
+ {
+ error (0, errno, "flushing file");
+ cleanup ();
+ exit (2);
+ }
+
if (fp != stdin && fp != stdout)
{
if (fclose (fp) != 0)
@@ -274,8 +280,10 @@ xfclose (fp)
}
}
else
- /* Allow reading stdin from tty more than once. */
- clearerr (fp);
+ {
+ /* Allow reading stdin from tty more than once. */
+ clearerr (fp);
+ }
}
static void
@@ -1797,12 +1805,12 @@ main (argc, argv)
Solaris, Ultrix, and Irix. This premature fflush makes the output
reappear. --karl@cs.umb.edu */
if (fflush (ofp) < 0)
- error (1, errno, "fflush", outfile);
+ error (1, errno, "%s: write error", outfile);
if (have_read_stdin && fclose (stdin) == EOF)
- error (1, errno, "-");
+ error (1, errno, outfile);
if (ferror (stdout) || fclose (stdout) == EOF)
- error (1, errno, "write error");
+ error (1, errno, "%s: write error", outfile);
exit (0);
}