Subject: bug#6657: mkstemp on cygwin creates binary files

From: Eric Blake <[email-masked]>
Date: Mon, 19 Jul 2010 10:33:32 -0600

On 07/19/2010 10:31 AM, Paolo Bonzini wrote:
> On 07/19/2010 03:28 PM, Eric Blake wrote:
>> By the way, I don't see your patch for using mkostemp on cygwin in
>> git://git.sv.gnu.org/sed.git; am I missing something, or is that not the
>> latest git repository for sed?
> 
> I wanted to make sure you liked it before pushing. :)  I'll now push it.
> 
> I also experimented with forcing "wt" or "wb" depending on the presence
> or absence of --binary, but I convinced myself that at least using "wt"
> is wrong.
> 
> For now, I won't change the behavior of building the file in /tmp. While
> this may make rename not atomic, it can be "corrected" anyway by setting
> TMPDIR=. in the environment.

Yuck - that means if /tmp is mounted differently than ., then using
mkostemp(,0) will force the wrong line endings (converting binary to
text, or converting text to binary, depending on which direction the
mismatch is between the mount modes).  If you aren't creating the temp
file in the same mount point as the target, then you cannot blindly rely
on automatic mount point file modes to do the right thing.

-- 
Eric Blake   [email-masked]    +1-801-349-2682
Libvirt virtualization library http://libvirt.org