From 8a350e90dc8d047e8372a53dd64fc178157b3f52 Mon Sep 17 00:00:00 2001
From: Ken Brown
Date: Thu, 27 Jun 2019 14:54:09 -0400
Subject: [PATCH 1/2] Avoid O_PATH on versions of Cygwin where it is buggy
* src/dired.c [O_PATH] (use_o_path): New function.
(file_attributes): Use it. (Bug#99999)
---
src/dired.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/src/dired.c b/src/dired.c
index 493758292b..ac83a026de 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -36,6 +36,10 @@
#include
#include
+#if defined CYGWIN && defined O_PATH
+#include
+#endif
+
#include "lisp.h"
#include "systime.h"
#include "buffer.h"
@@ -921,6 +925,21 @@ DEFUN ("file-attributes", Ffile_attributes, Sfile_attributes, 1, 2, 0,
id_format);
}
+/* Cygwin supports O_PATH starting with release 3.0.0, but it is buggy
+ until release 3.0.8. */
+#ifdef O_PATH
+static bool
+use_o_path (void)
+{
+# ifdef CYGWIN
+ struct utsname name;
+ return uname (&name) >= 0 && strverscmp (name.release, "3.0.8") >= 0;
+# else
+ return true;
+# endif
+}
+#endif
+
static Lisp_Object
file_attributes (int fd, char const *name,
Lisp_Object dirname, Lisp_Object filename,
@@ -938,6 +957,8 @@ file_attributes (int fd, char const *name,
int err = EINVAL;
#ifdef O_PATH
+ if (use_o_path ())
+ {
int namefd = openat (fd, name, O_PATH | O_CLOEXEC | O_NOFOLLOW);
if (namefd < 0)
err = errno;
@@ -960,6 +981,7 @@ file_attributes (int fd, char const *name,
name = "";
}
}
+ }
#endif
if (err == EINVAL)
--
2.21.0