Subject: Re: bug#15015: Fix some minor races in hosts lacking mkostemp

From: Paul Eggert <[email-masked]>
Date: Sat, 03 Aug 2013 07:40:35 -0700

On 08/03/2013 01:38 AM, Eli Zaretskii wrote:

> the gnulib mkostemp module ... relies on quite a few functions that are
> redefined in Emacs, and I have no idea what will this do to the gnulib
> implementation.

I don't see the problem; could you please explain further?
On Microsoft platforms, the only functions that the mkostemp
module should use should be getenv, strlen, memcmp,
gettimeofday, open (..., O_RDWR | O_CREAT | O_EXCL, S_IRUSR
| S_IWUSR), and lstat, and this sort of thing is already
working elsewhere.  mkostemp calls mkdir but that call is
never used by Emacs so as long as it compiles we should be
OK.

> Also, since we still didn't remove the support for
> MS-Windows builds that use nt/configure.bat and the makefile-w32.in
> files, the uses of mktemp in the Emacs sources should be left alone
> for now, if we go this route.

Presumably nt/configure.bat and makefile-w32.in could be updated
to compile the new files.  This sort of thing should be routine,
if that avenue is still supported.

> I thought of a far easier solution: use the same code as sys_mktemp
> does, but use 'open' or '_sopen' instead of faccessat.

This won't suffice for POSIXish platforms that lack mkostemp
but have 'open' with O_EXCL.  Solaris is one example.  The
Gnulib mkostemp module fixes the races on those platforms.

> alternatively, we could add an implementation of 'mkostemp'
> in msdos.c.

Sure, that should work fine.  The MS-DOS port need not compile
the new lib/*.c files.