From: Bruno Haible Date: Mon, 5 Jun 2023 09:15:37 +0000 (+0200) Subject: Fix bugs on mingw when module dirfd is in use (regression 2023-04-26). X-Git-Tag: v1.0~1250 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=dc1b410b9ab160fb51f316bdc32def98499d1b17;p=gnulib.git 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/ChangeLog b/ChangeLog index 9a30a0fb8a..9554071224 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2023-06-05 Bruno Haible + + 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. + 2023-06-04 Bruno Haible manywarnings: Overhaul documentation. 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