Eric Blake <ebb9 <at> byu.net> writes:
> if (status == EXIT_SUCCESS)
> - puts (dest_name);
> + {
> + puts (dest_name);
> + /* If we created a file, but then failed to output the file
> + name, we should clean up the mess before failing. */
> + if (!dry_run && close_stream (stdout))
> + {
> + remove (dest_name);
> + error (EXIT_FAILURE, errno, _("write error"));
The remove() can corrupt errno, so I'm squashing this on top:
diff --git i/src/mktemp.c w/src/mktemp.c
index 12acad8..049401f 100644
--- i/src/mktemp.c
+++ w/src/mktemp.c
@@ -329,8 +329,9 @@ main (int argc, char **argv)
name, we should clean up the mess before failing. */
if (!dry_run && close_stream (stdout))
{
+ int saved_errno = errno;
remove (dest_name);
- error (EXIT_FAILURE, errno, _("write error"));
+ error (EXIT_FAILURE, saved_errno, _("write error"));
}
}
--
Eric Blake