From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 5F12839C5022; Fri, 12 Feb 2021 09:18:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F12839C5022 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: Have tmpfile(3) use O_TMPFILE X-Act-Checkin: newlib-cygwin X-Git-Author: Mark Geisert X-Git-Refname: refs/heads/master X-Git-Oldrev: 5fea2f87dcb4d64f25072cc66d8909c7945e2345 X-Git-Newrev: 62ee6581a5701342c17790116f847e9d40c387d7 Message-Id: <20210212091842.5F12839C5022@sourceware.org> Date: Fri, 12 Feb 2021 09:18:42 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Feb 2021 09:18:42 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=62ee6581a5701342c17790116f847e9d40c387d7 commit 62ee6581a5701342c17790116f847e9d40c387d7 Author: Mark Geisert Date: Wed Feb 10 22:53:05 2021 -0800 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. Diff: --- winsup/cygwin/release/3.2.0 | 4 ++++ winsup/cygwin/syscalls.cc | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/winsup/cygwin/release/3.2.0 b/winsup/cygwin/release/3.2.0 index f748a9bc8..d02d16863 100644 --- a/winsup/cygwin/release/3.2.0 +++ b/winsup/cygwin/release/3.2.0 @@ -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 --------- diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 52a020f07..d04b2d9b3 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -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)