bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: temp file suffixes: mktemp DWIM


From: Eric Blake
Subject: Re: temp file suffixes: mktemp DWIM
Date: Wed, 4 Nov 2009 21:19:13 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

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







reply via email to

[Prev in Thread] Current Thread [Next in Thread]