]> sourceware.org Git - newlib-cygwin.git/commitdiff
Cygwin: Have tmpfile(3) use O_TMPFILE
authorMark Geisert <mark@maxrnd.com>
Thu, 11 Feb 2021 06:53:05 +0000 (22:53 -0800)
committerCorinna Vinschen <corinna@vinschen.de>
Fri, 12 Feb 2021 09:18:25 +0000 (10:18 +0100)
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.

winsup/cygwin/release/3.2.0
winsup/cygwin/syscalls.cc

index f748a9bc8a6e110105c1b06cdd3687a40725978c..d02d168637af2530c8009994aa6d92fba4dea1d2 100644 (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
 ---------
index 52a020f07d5e2f873b59c4b88c6d57656a1ce8d3..d04b2d9b3ce21f5a9f11edc1c8505b27b77f2ef3 100644 (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)
This page took 0.035231 seconds and 5 git commands to generate.