bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Do not assume glibc glob internals


From: Paul Eggert
Subject: [PATCH] Do not assume glibc glob internals
Date: Sun, 10 Sep 2017 09:40:13 -0700

It has been proposed that glibc glob start using gl_lstat,
which the API allows it to do.  GNU 'make' should not get in
the way of this.  See:
https://sourceware.org/ml/libc-alpha/2017-09/msg00409.html
* dir.c (local_lstat): New function, like local_stat.
(dir_setup_glob): Use it to initialize gl_lstat too, as the API
requires.
---
 dir.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 42 insertions(+), 2 deletions(-)

diff --git a/dir.c b/dir.c
index adbb8a9..25d5ca3 100644
--- a/dir.c
+++ b/dir.c
@@ -1299,15 +1299,55 @@ local_stat (const char *path, struct stat *buf)
 }
 #endif
 
+/* Similarly for lstat.  */
+#if !defined(lstat) && !defined(WINDOWS32) || defined(VMS)
+# ifndef VMS
+#  ifndef HAVE_SYS_STAT_H
+int lstat (const char *path, struct stat *sbuf);
+#  endif
+# else
+    /* We are done with the fake lstat.  Go back to the real lstat */
+#   ifdef lstat
+#     undef lstat
+#   endif
+# endif
+# define local_lstat lstat
+#else
+static int
+local_lstat (const char *path, struct stat *buf)
+{
+  int e;
+#ifdef WINDOWS32
+  size_t plen = strlen (path);
+
+  /* Make sure the parent of "." exists and is a directory, not a
+     file.  This is because 'lstat' on Windows normalizes the argument
+     foo/. => foo without checking first that foo is a directory.  */
+  if (plen > 1 && path[plen - 1] == '.'
+      && (path[plen - 2] == '/' || path[plen - 2] == '\\'))
+    {
+      char parent[MAXPATHLEN];
+
+      strncpy (parent, path, plen - 2);
+      parent[plen - 2] = '\0';
+      if (lstat (parent, buf) < 0 || !_S_ISDIR (buf->st_mode))
+        return -1;
+    }
+#endif
+
+  EINTRLOOP (e, lstat (path, buf));
+  return e;
+}
+#endif
+
 void
 dir_setup_glob (glob_t *gl)
 {
   gl->gl_opendir = open_dirstream;
   gl->gl_readdir = read_dirstream;
   gl->gl_closedir = free;
+  gl->gl_lstat = local_lstat;
   gl->gl_stat = local_stat;
-  /* We don't bother setting gl_lstat, since glob never calls it.
-     The slot is only there for compatibility with 4.4 BSD.  */
 }
 
 void
-- 
2.13.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]