bug-coreutils
[Top][All Lists]
Advanced

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

Re: [PATCHv2 0/7] Re: temp file suffixes: mktemp DWIM


From: Jim Meyering
Subject: Re: [PATCHv2 0/7] Re: temp file suffixes: mktemp DWIM
Date: Thu, 05 Nov 2009 16:28:52 +0100

Jim Meyering wrote:

> Eric Blake wrote:
>
>> According to Jim Meyering on 11/5/2009 2:35 AM:
>>> Nice work!
>>> Modulo tiny comments, you're welcome to push that series
>>> once you've pushed the gnulib bits upon which it depends.
>>
>> Aargh.  I just noticed that what I pushed still has a bug:
>>
>> $ src/mktemp -u XXXXXXXXXXXXXXXXX.pdf
>> XXXXXXXXXXXXXpiYD.pdf
>>
>> Rather than replacing all the X, it is only replacing the number of X in
>> the suffix.  And the testsuite didn't catch it :(
>>
>> I'll have to prepare a followup patch, but I ran out of time this morning.
>
> Here's at least part of it:
>
> diff --git a/src/mktemp.c b/src/mktemp.c
> index ac35026..f60e824 100644
> --- a/src/mktemp.c
> +++ b/src/mktemp.c
> @@ -118,14 +118,14 @@ static int
>  mkstemp_len (char *tmpl, size_t suff_len, size_t x_len, bool dry_run)
>  {
>    return gen_tempname_len (tmpl, suff_len, 0, dry_run ? GT_NOCREATE : 
> GT_FILE,
> -                           suff_len);
> +                           x_len);
>  }
>
>  static int
>  mkdtemp_len (char *tmpl, size_t suff_len, size_t x_len, bool dry_run)
>  {
>    return gen_tempname_len (tmpl, suff_len, 0, dry_run ? GT_NOCREATE : GT_DIR,
> -                           suff_len);
> +                           x_len);
>  }
>
>  int

And this is the final required change:

    $ ./mktemp foo-XXX
    foo-dgc
    ./mktemp: write error

>From 9300d6e0cc1e221dcedfa68f17144a47402c6741 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Thu, 5 Nov 2009 16:26:19 +0100
Subject: [PATCH] mktemp: don't try to close stdout twice

* src/mktemp.c (main): Rather than calling close_stream (which would
make atexit-called close_stdout try to close it a second time),
check for write failure via ferror and fflush.
---
 src/mktemp.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/mktemp.c b/src/mktemp.c
index f60e824..980ec39 100644
--- a/src/mktemp.c
+++ b/src/mktemp.c
@@ -325,7 +325,7 @@ main (int argc, char **argv)
       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))
+      if (!dry_run && (ferror (stdout) || fflush (stdout) != 0))
         {
           int saved_errno = errno;
           remove (dest_name);
--
1.6.5.2.303.g13162




reply via email to

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