Cygwin: Have tmpfile(3) use O_TMPFILE

Per discussion on cygwin-developers, a Cygwin tmpfile(3) implementation
has been added to syscalls.cc.  This overrides the one supplied by
newlib.  Then the open(2) flag O_TMPFILE was added to the open call that
tmpfile internally makes.

This v2 patch removes O_CREAT from open() call as O_TMPFILE obviates it.
Note that open() takes a directory's path but returns an fd to a file.
This commit is contained in:
Mark Geisert 2021-02-10 22:53:05 -08:00 committed by Corinna Vinschen
parent 5fea2f87dc
commit 62ee6581a5
2 changed files with 23 additions and 0 deletions

View File

@ -19,6 +19,10 @@ What changed:
- A few FAQ updates.
- Have tmpfile(3) make use of Win32 FILE_ATTRIBUTE_TEMPORARY via open(2)
flag O_TMPFILE.
Addresses: https://cygwin.com/pipermail/cygwin/2021-January/247304.html
Bug Fixes
---------

View File

@ -5225,3 +5225,22 @@ pipe2 (int filedes[2], int mode)
syscall_printf ("%R = pipe2([%d, %d], %y)", res, read, write, mode);
return res;
}
extern "C" FILE *
tmpfile (void)
{
char *dir = getenv ("TMPDIR");
if (!dir)
dir = P_tmpdir;
int fd = open (dir, O_RDWR | O_BINARY | O_TMPFILE, S_IRUSR | S_IWUSR);
if (fd < 0)
return NULL;
FILE *fp = fdopen (fd, "wb+");
int e = errno;
if (!fp)
close (fd); // ..will remove tmp file
set_errno (e);
return fp;
}
EXPORT_ALIAS (tmpfile, tmpfile64)