[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fix bugs on mingw when module dirfd is in use
From: |
Bruno Haible |
Subject: |
Fix bugs on mingw when module dirfd is in use |
Date: |
Mon, 05 Jun 2023 11:20:44 +0200 |
Building gettext on mingw, I see these warnings:
gettext-tools/gnulib-lib/getcwd.c:293:36: warning: passing argument 1 of
'closedir' from incompatible pointer type [-Wincompatible-pointer-types]
gettext-tools/gnulib-lib/getcwd.c:311:17: warning: assignment from incompatible
pointer type [-Wincompatible-pointer-types]
gettext-tools/gnulib-lib/getcwd.c:507:32: warning: passing argument 1 of
'closedir' from incompatible pointer type [-Wincompatible-pointer-types]
gettext-tools/gnulib-lib/getcwd.c:541:19: warning: passing argument 1 of
'closedir' from incompatible pointer type [-Wincompatible-pointer-types]
The cause is that the 'dirfd' support for native Windows (from 2023-04-26)
overrides DIR and all related functions. But the code in getcwd.c undefines
only opendir and closedir. The net result is that getcwd.o depends on the
functions opendir, closedir, rpl_readdir, rpl_rewinddir; this will not work
at runtime, since the overridden DIR is not pointer-compatible with the
original DIR.
This patch fixes it.
2023-06-05 Bruno Haible <bruno@clisp.org>
Fix bugs on mingw when module dirfd is in use (regression 2023-04-26).
* lib/getcwd.c: When GNULIB_defined_DIR, revert to the system's
definitions of opendir, closedir, readdir, rewinddir.
* lib/mountlist.c: When GNULIB_defined_DIR, revert to the system's
definitions of opendir, closedir, readdir.
* lib/scandir.c: Likewise.
* lib/glob.c: Fix comment. When GNULIB_defined_DIR, don't undefine
opendir, closedir.
diff --git a/lib/getcwd.c b/lib/getcwd.c
index 0530630c43..28f69133a8 100644
--- a/lib/getcwd.c
+++ b/lib/getcwd.c
@@ -114,13 +114,21 @@
FIXME - if the kernel ever adds support for multi-thread safety for
avoiding standard fds, then we should use opendir_safer and
openat_safer. */
-#ifdef GNULIB_defined_opendir
+#ifdef GNULIB_defined_DIR
+# undef DIR
# undef opendir
-#endif
-#ifdef GNULIB_defined_closedir
# undef closedir
+# undef readdir
+# undef rewinddir
+#else
+# ifdef GNULIB_defined_opendir
+# undef opendir
+# endif
+# ifdef GNULIB_defined_closedir
+# undef closedir
+# endif
#endif
-
+
#if defined _WIN32 && !defined __CYGWIN__
# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
static char *
diff --git a/lib/glob.c b/lib/glob.c
index ddca1e9820..af0694eec4 100644
--- a/lib/glob.c
+++ b/lib/glob.c
@@ -182,16 +182,17 @@ convert_dirent64 (const struct dirent64 *source)
#endif
#ifndef _LIBC
-/* The results of opendir() in this file are not used with dirfd and fchdir,
- and we do not leak fds to any single-threaded code that could use stdio,
- 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. */
-# ifdef GNULIB_defined_opendir
-# undef opendir
-# endif
-# ifdef GNULIB_defined_closedir
-# undef closedir
+/* The results of opendir() in this file are used with dirfd. But they are
+ not used with fchdir, and we do not leak fds to any single-threaded code
+ that could use stdio, therefore save some unnecessary recursion in
+ fchdir.c and opendir_safer.c. */
+# ifndef GNULIB_defined_DIR
+# ifdef GNULIB_defined_opendir
+# undef opendir
+# endif
+# ifdef GNULIB_defined_closedir
+# undef closedir
+# endif
# endif
/* Just use malloc. */
diff --git a/lib/mountlist.c b/lib/mountlist.c
index 6d38481284..8b06e7b7ee 100644
--- a/lib/mountlist.c
+++ b/lib/mountlist.c
@@ -154,11 +154,18 @@
/* The results of opendir() in this file are not used with dirfd and fchdir,
therefore save some unnecessary work in fchdir.c. */
-#ifdef GNULIB_defined_opendir
+#ifdef GNULIB_defined_DIR
+# undef DIR
# undef opendir
-#endif
-#ifdef GNULIB_defined_closedir
# undef closedir
+# undef readdir
+#else
+# ifdef GNULIB_defined_opendir
+# undef opendir
+# endif
+# ifdef GNULIB_defined_closedir
+# undef closedir
+# endif
#endif
#define ME_DUMMY_0(Fs_name, Fs_type) \
diff --git a/lib/scandir.c b/lib/scandir.c
index 9d582e7ac3..429067ed74 100644
--- a/lib/scandir.c
+++ b/lib/scandir.c
@@ -62,8 +62,19 @@
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_DIR
+# undef DIR
+# undef opendir
+# undef closedir
+# undef readdir
+# else
+# ifdef GNULIB_defined_opendir
+# undef opendir
+# endif
+# ifdef GNULIB_defined_closedir
+# undef closedir
+# endif
+# endif
#endif
#ifndef SCANDIR_CANCEL
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Fix bugs on mingw when module dirfd is in use,
Bruno Haible <=