Brian Inglis
Wed Jan 6 17:16:28 GMT 2021

On 2021-01-06 02:44, Mark Geisert wrote:
> Hi Noel,
> Noel Grandin via Cygwin wrote:
>> Hi
>> Does the cygwin
>>      tempfile()
>> API use the Win32
>> flag on the files it creates?
>> Asking because that makes a fairly significant performance difference when 
>> creating very short lived temp files.
> Good question!  If one specifies O_TMPFILE as one of the flags on an open() 
> call, Cygwin does set that Win32 attribute as desired.  Unfortunately, Cygwin's 
> tmpfile() is supplied by newlib and it does not specify O_TMPFILE on its 
> underlying open() call.
> That looks like a bug to me, unless I'm missing something subtle there; I'll 
> submit a patch and find out.

O_TMPFILE is only implemented under winsup/cygwin, and only defined for newlib 
under Cygwin:;a=blob;f=newlib/libc/include/sys/_default_fcntl.h



You should allow linkat to reverse the applied attributes to make the file 
permanent, which may be taken care of in the patch above to 
from Linux open(2) see

"O_TMPFILE must be specified with one of O_RDWR or O_WRONLY and,
optionally, O_EXCL. If O_EXCL is not specified, then linkat(2) can be
used to link the temporary file into the filesystem, making it
permanent, using code like the following:

	char path[PATH_MAX];
	fd = open("/path/to/dir", O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR);

	/* File I/O on 'fd'... */

	snprintf(path, PATH_MAX, "/proc/self/fd/%d", fd);
	linkat(AT_FDCWD, path, AT_FDCWD, "/path/for/file",

although the implementation may not currently handle O_EXCL.

Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.
[Data in binary units and prefixes, physical quantities in SI.]

More information about the Cygwin mailing list