public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin-patches@cygwin.com
Subject: Re: [PATCH] Cygwin: Have tmpfile(3) use O_TMPFILE
Date: Tue, 9 Feb 2021 16:25:10 +0100	[thread overview]
Message-ID: <20210209152510.GV4251@calimero.vinschen.de> (raw)
In-Reply-To: <20210209105000.26544-1-mark@maxrnd.com>

Hi Mark,

On Feb  9 02:50, Mark Geisert wrote:
> 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.
> ---
>  winsup/cygwin/release/3.2.0 |  4 ++++
>  winsup/cygwin/syscalls.cc   | 20 ++++++++++++++++++++
>  2 files changed, 24 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..b79c1c7cd 100644
> --- a/winsup/cygwin/syscalls.cc
> +++ b/winsup/cygwin/syscalls.cc
> @@ -5225,3 +5225,23 @@ 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");

This isn't what Linux tmpfile does.  Per the man page, it tries to
create the file in P_tmpdir first, and if that fails, it tries
"/tmp".

> +  if (!dir)
> +    dir = P_tmpdir;
> +  int fd = open (dir, O_RDWR | O_CREAT | O_BINARY | O_TMPFILE,

You have to specify O_EXCL here.  The idea is that this file cannot be
made permanent, and missing the O_EXCL flag allows exactly that.  See
https://man7.org/linux/man-pages/man2/open.2.html, the lengthy
description in terms of O_TMPFILE.


Thanks,
Corinna

  reply	other threads:[~2021-02-09 15:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-09 10:50 Mark Geisert
2021-02-09 15:25 ` Corinna Vinschen [this message]
2021-02-10  9:07   ` Mark Geisert
2021-02-10 10:12     ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210209152510.GV4251@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=cygwin-patches@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).