How about the attached patch instead?
>From f386f157997182fa54c5ff408233f42a3ef6d0ed Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Tue, 24 Feb 2015 20:44:32 -0800
Subject: [PATCH] glob, etc.: port to MSVC v18 on MS-Windows 8.1

* lib/dirent--.h (GNULIB_defined_opendir):
* lib/dirent.in.h (GNULIB_defined_opendir)
(GNULIB_defined_closedir):
* lib/getcwd.c, lib/glob.c, lib/mountlist.c (opendir, closedir):
#undef only if Gnulib defined it.
---
 ChangeLog       | 7 +++++++
 lib/dirent--.h  | 1 +
 lib/dirent.in.h | 2 ++
 lib/getcwd.c    | 8 ++++++--
 lib/glob.c      | 8 ++++++--
 lib/mountlist.c | 8 ++++++--
 6 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 42351a6..86bab16 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2015-02-24  Paul Eggert  <[email protected]>
 
+	glob, etc.: port to MSVC v18 on MS-Windows 8.1
+	* lib/dirent--.h (GNULIB_defined_opendir):
+	* lib/dirent.in.h (GNULIB_defined_opendir)
+	(GNULIB_defined_closedir):
+	* lib/getcwd.c, lib/glob.c, lib/mountlist.c (opendir, closedir):
+	#undef only if Gnulib defined it.
+
 	poll: port to MSVC v18 on MS-Windows 8.1
 	Problem reported by Gisle Vanem in:
 	http://lists.gnu.org/archive/html/bug-gnulib/2015-02/msg00139.html
diff --git a/lib/dirent--.h b/lib/dirent--.h
index 17a8853..aa3f492 100644
--- a/lib/dirent--.h
+++ b/lib/dirent--.h
@@ -21,3 +21,4 @@
 
 #undef opendir
 #define opendir opendir_safer
+#define GNULIB_defined_opendir 1
diff --git a/lib/dirent.in.h b/lib/dirent.in.h
index ddd3b84..154d268 100644
--- a/lib/dirent.in.h
+++ b/lib/dirent.in.h
@@ -77,6 +77,7 @@ typedef struct gl_directory DIR;
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef opendir
 #   define opendir rpl_opendir
+#   define GNULIB_defined_opendir 1
 #  endif
 _GL_FUNCDECL_RPL (opendir, DIR *, (const char *dir_name) _GL_ARG_NONNULL ((1)));
 _GL_CXXALIAS_RPL (opendir, DIR *, (const char *dir_name));
@@ -128,6 +129,7 @@ _GL_WARN_ON_USE (rewinddir, "rewinddir is not portable - "
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef closedir
 #   define closedir rpl_closedir
+#   define GNULIB_defined_closedir 1
 #  endif
 _GL_FUNCDECL_RPL (closedir, int, (DIR *dirp) _GL_ARG_NONNULL ((1)));
 _GL_CXXALIAS_RPL (closedir, int, (DIR *dirp));
diff --git a/lib/getcwd.c b/lib/getcwd.c
index 20efabd..db5279d 100644
--- a/lib/getcwd.c
+++ b/lib/getcwd.c
@@ -93,8 +93,12 @@
    FIXME - if the kernel ever adds support for multi-thread safety for
    avoiding standard fds, then we should use opendir_safer and
    openat_safer.  */
-#undef opendir
-#undef closedir
+#ifdef GNULIB_defined_opendir
+# undef opendir
+#endif
+#ifdef GNULIB_defined_closedir
+# undef closedir
+#endif
 
 /* Get the name of the current working directory, and put it in SIZE
    bytes of BUF.  Returns NULL if the directory couldn't be determined or
diff --git a/lib/glob.c b/lib/glob.c
index f13cb8a..ed49a9d 100644
--- a/lib/glob.c
+++ b/lib/glob.c
@@ -188,8 +188,12 @@ static const char *next_brace_sub (const char *begin, int flags) __THROWNL;
    therefore save some unnecessary recursion in fchdir.c and opendir_safer.c.
    FIXME - if the kernel ever adds support for multi-thread safety for
    avoiding standard fds, then we should use opendir_safer.  */
-# undef opendir
-# undef closedir
+# ifdef GNULIB_defined_opendir
+#  undef opendir
+# endif
+# ifdef GNULIB_defined_closedir
+#  undef closedir
+# endif
 
 # if HAVE_ALLOCA
 /* The OS usually guarantees only one guard page at the bottom of the stack,
diff --git a/lib/mountlist.c b/lib/mountlist.c
index 6fed357..dce4ce6 100644
--- a/lib/mountlist.c
+++ b/lib/mountlist.c
@@ -157,8 +157,12 @@
 
 /* The results of opendir() in this file are not used with dirfd and fchdir,
    therefore save some unnecessary work in fchdir.c.  */
-#undef opendir
-#undef closedir
+#ifdef GNULIB_defined_opendir
+# undef opendir
+#endif
+#ifdef GNULIB_defined_closedir
+# undef closedir
+#endif
 
 #define ME_DUMMY_0(Fs_name, Fs_type)            \
   (strcmp (Fs_type, "autofs") == 0              \
-- 
2.1.0

Reply via email to