public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org, newlib-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: linkat: support Linux-specific AT_EMPTY_PATH flag
Date: Mon, 07 Jan 2019 18:37:00 -0000	[thread overview]
Message-ID: <20190107183703.737.qmail@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=9443efe0990ad32c1896717ac7c38ff9c8c57073

commit 9443efe0990ad32c1896717ac7c38ff9c8c57073
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Mon Jan 7 19:36:37 2019 +0100

    Cygwin: linkat: support Linux-specific AT_EMPTY_PATH flag
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 newlib/libc/include/sys/_default_fcntl.h |  1 +
 winsup/cygwin/release/2.12.0             |  2 ++
 winsup/cygwin/syscalls.cc                | 20 ++++++++++++++++++--
 winsup/doc/new-features.xml              |  4 ++++
 4 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/newlib/libc/include/sys/_default_fcntl.h b/newlib/libc/include/sys/_default_fcntl.h
index 2dc0068..0647e59 100644
--- a/newlib/libc/include/sys/_default_fcntl.h
+++ b/newlib/libc/include/sys/_default_fcntl.h
@@ -166,6 +166,7 @@ extern "C" {
 #define AT_SYMLINK_NOFOLLOW     2
 #define AT_SYMLINK_FOLLOW       4
 #define AT_REMOVEDIR            8
+#define AT_EMPTY_PATH          16
 #endif
 
 #if __BSD_VISIBLE
diff --git a/winsup/cygwin/release/2.12.0 b/winsup/cygwin/release/2.12.0
index c9e63a6..81a55b5 100644
--- a/winsup/cygwin/release/2.12.0
+++ b/winsup/cygwin/release/2.12.0
@@ -22,6 +22,8 @@ What's new:
 
 - Support Linux-specific open(2) flag O_PATH.
 
+- Support Linux-specific linkat(2) flag AT_EMPTY_PATH.
+
 
 What changed:
 -------------
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index d6f81ca..cb62a62 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -4812,13 +4812,29 @@ linkat (int olddirfd, const char *oldpathname,
   tmp_pathbuf tp;
   __try
     {
-      if (flags & ~AT_SYMLINK_FOLLOW)
+      if (flags & ~(AT_SYMLINK_FOLLOW | AT_EMPTY_PATH))
 	{
 	  set_errno (EINVAL);
 	  __leave;
 	}
       char *oldpath = tp.c_get ();
-      if (gen_full_path_at (oldpath, olddirfd, oldpathname))
+      /* AT_EMPTY_PATH with an empty oldpathname is equivalent to
+
+	   linkat(AT_FDCWD, "/proc/self/fd/<olddirfd>", newdirfd,
+		  newname, AT_SYMLINK_FOLLOW);
+
+	 Convert the request accordingly. */
+      if ((flags & AT_EMPTY_PATH) && oldpathname && oldpathname[0] == '\0')
+	{
+	  if (olddirfd == AT_FDCWD)
+	    {
+	      set_errno (EPERM);
+	      __leave;
+	    }
+	  __small_sprintf (oldpath, "/proc/%d/fd/%d", myself->pid, olddirfd);
+	  flags = AT_SYMLINK_FOLLOW;
+	}
+      else if (gen_full_path_at (oldpath, olddirfd, oldpathname))
 	__leave;
       char *newpath = tp.c_get ();
       if (gen_full_path_at (newpath, newdirfd, newpathname))
diff --git a/winsup/doc/new-features.xml b/winsup/doc/new-features.xml
index b55e031..f84a9c4 100644
--- a/winsup/doc/new-features.xml
+++ b/winsup/doc/new-features.xml
@@ -42,6 +42,10 @@ Support Linux-specific open(2) flag O_PATH.
 </para></listitem>
 
 <listitem><para>
+- Support Linux-specific linkat(2) flag AT_EMPTY_PATH.
+</para></listitem>
+
+<listitem><para>
 clock_nanosleep, pthread_condattr_setclock and timer_create now support
 all clocks, except CLOCK_PROCESS_CPUTIME_ID and CLOCK_THREAD_CPUTIME_ID.
 </para></listitem>


                 reply	other threads:[~2019-01-07 18:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20190107183703.737.qmail@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    --cc=newlib-cvs@sourceware.org \
    /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).