GNU bug report logs - #6657
mkstemp on cygwin creates binary files

Previous Next

Package: coreutils;

Reported by: Paolo Bonzini <bonzini <at> gnu.org>

Date: Fri, 16 Jul 2010 20:40:02 UTC

Severity: normal

Done: Jim Meyering <jim <at> meyering.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Eric Blake <eblake <at> redhat.com>
To: Paolo Bonzini <bonzini <at> gnu.org>
Cc: 6657 <at> debbugs.gnu.org, Paul Eggert <eggert <at> CS.UCLA.EDU>
Subject: bug#6657: mkstemp on cygwin creates binary files
Date: Sat, 17 Jul 2010 17:54:25 -0600
[Message part 1 (text/plain, inline)]
On 07/17/2010 12:13 AM, Paolo Bonzini wrote:
>> I don't see the problem with 'sort' offhand.  Why would the user care
>> whether
>> line endings in sort's temp files are \r\n or \n?  Using binary mode is a
>> bit faster and more reliable, surely.

Correct.  I see no reason to change sort.

>>
>> Or is there some problem if the file descriptor is created with O_BINARY
>> and then fdopen is called with "w" (and not "wb")?  I guess "sort" does
>> that on Cygwin now.
> 
> No idea.  I just thought a heads-up was in order...

fdopen(,"w") on cygwin honors the existing O_TEXT or O_BINARY flag of
the underlying fd; while only fdopen(,"wt") and fdopen(,"wb") force the
flag (and changes the flag of the underlying fd, if needed).

The problem with sed was that the temp file was then being rename()d
into the original file name, regardless of whether the final file should
be binary or text.  sort does not have the problem, because the
temporary file was truly temporary - it is not renamed into a
user-visible file after it is used.

By the way, newer cygwin provides mkostemp() - did you only fix the
problem for older cygwin that lacks mkostemp and thus gets the gnulib
fallback that doesn't force binary?  And what's wrong with using
setmode() (from <io.h>, or from gnulib's "binary-io.h") on the fd
created by mkstemp() to ensure the desired mode, rather than having to
use mkostemp?

-- 
Eric Blake   eblake <at> redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-- 
Eric Blake   eblake <at> redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

This bug report was last modified 13 years and 315 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.