diff options
author | Bruno Haible <bruno@clisp.org> | 2023-04-27 01:42:25 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2023-04-27 01:42:25 +0200 |
commit | 3f0950f65abb5162c42b51a9bb32c9e87deeb405 (patch) | |
tree | bd2794c98d44013cf67c6b39c0863054315ebd68 /modules | |
parent | d70f555e34d9f4a9110e65dd5669fce701a61929 (diff) | |
download | gnulib-3f0950f65abb5162c42b51a9bb32c9e87deeb405.tar.gz |
fdopendir: Fix fd leak and test failure on native Windows.
* lib/dirent-private.h: On mingw, define 'struct gl_directory' as a
wrapper around the original DIR. On MSVC, add an 'fd_to_close' field to
'struct gl_directory'.
* lib/dirent.in.h (DIR): Define when DIR_HAS_FD_MEMBER is 0, i.e. on
both mingw and MSVC.
(GNULIB_defined_DIR): New macro.
(opendir): Avoid incompatible redeclaration.
(readdir): Consider REPLACE_READDIR.
(rewinddir): Consider REPLACE_REWINDDIR.
* m4/dirent_h.m4 (gl_DIRENT_DIR): New macro.
(gl_DIRENT_H): Invoke it.
(gl_DIRENT_H_DEFAULTS): Initialize REPLACE_READDIR, REPLACE_REWINDDIR.
* modules/dirent (Makefile.am): Substitute DIR_HAS_FD_MEMBER,
REPLACE_READDIR, REPLACE_REWINDDIR.
--
* lib/dirfd.c (dirfd): If GNULIB_defined_DIR, just use the
'fd_to_close' field.
* m4/dirfd.m4 (gl_FUNC_DIRFD): Set HAVE_DIRFD. Don't set REPLACE_DIRFD
to 1 if HAVE_DIRFD is 0. If DIR_HAS_FD_MEMBER is 0, ensure dirfd.c gets
compiled.
* modules/dirfd (Files): Add lib/dirent-private.h.
(Depends-on, configure.ac): Simplify conditions.
--
* lib/closedir.c: Include <stdlib.h> always, for free().
(closedir): If GNULIB_defined_DIR, arrange to call close(dirfd(dirp)) at
the end. On mingw, call free() of dirp. Prefer testing HAVE_DIRENT_H,
for consistency with dirent.h.
* m4/closedir.m4 (gl_FUNC_CLOSEDIR): Don't set REPLACE_CLOSEDIR to 1 if
HAVE_CLOSEDIR is 0. If DIR_HAS_FD_MEMBER is 0, ensure closedir.c gets
compiled.
--
* lib/opendir.c: Include <stdlib.h> always. Include <string.h>.
(opendir): On mingw, allocate the 'struct gl_directory' through malloc.
If GNULIB_defined_DIR, set the 'fd_to_close' field to -1. Prefer
testing HAVE_DIRENT_H, for consistency with dirent.h.
* m4/opendir.m4 (gl_FUNC_OPENDIR): Don't set REPLACE_OPENDIR to 1 if
HAVE_OPENDIR is 0. If DIR_HAS_FD_MEMBER is 0, ensure opendir.c gets
compiled.
--
* lib/fdopendir.c (fdopendir): If GNULIB_defined_DIR, use a simple
implementation based on opendir and the fchdir module. If __KLIBC__,
don't define unused auxiliary functions.
* modules/fdopendir (Files): Add lib/dirent-private.h.
--
* lib/readdir.c (readdir): On mingw, redirect to the original readdir
function. Prefer testing HAVE_DIRENT_H, for consistency with dirent.h.
* m4/readdir.m4 (gl_FUNC_READDIR): If DIR_HAS_FD_MEMBER is 0, ensure
readdir.c gets compiled.
* modules/readdir (configure.ac): Consider REPLACE_READDIR.
--
* lib/rewinddir.c (rewinddir): On mingw, redirect to the original
rewinddir function. Prefer testing HAVE_DIRENT_H, for consistency with
dirent.h.
* m4/rewinddir.m4 (gl_FUNC_REWINDDIR): If DIR_HAS_FD_MEMBER is 0, ensure
rewinddir.c gets compiled.
* modules/rewinddir (configure.ac): Consider REPLACE_REWINDDIR.
--
* lib/fchdir.c (dir_info_t): Remove a FIXME.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/dirent | 3 | ||||
-rw-r--r-- | modules/dirfd | 5 | ||||
-rw-r--r-- | modules/fdopendir | 1 | ||||
-rw-r--r-- | modules/readdir | 3 | ||||
-rw-r--r-- | modules/rewinddir | 3 |
5 files changed, 11 insertions, 4 deletions
diff --git a/modules/dirent b/modules/dirent index 8ae7bbfc4e..6f5a63ad66 100644 --- a/modules/dirent +++ b/modules/dirent @@ -33,6 +33,7 @@ dirent.h: dirent.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ -e 's|@''NEXT_DIRENT_H''@|$(NEXT_DIRENT_H)|g' \ + -e 's/@''DIR_HAS_FD_MEMBER''@/$(DIR_HAS_FD_MEMBER)/g' \ -e 's/@''GNULIB_OPENDIR''@/$(GNULIB_OPENDIR)/g' \ -e 's/@''GNULIB_READDIR''@/$(GNULIB_READDIR)/g' \ -e 's/@''GNULIB_REWINDDIR''@/$(GNULIB_REWINDDIR)/g' \ @@ -51,6 +52,8 @@ dirent.h: dirent.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H -e 's|@''HAVE_SCANDIR''@|$(HAVE_SCANDIR)|g' \ -e 's|@''HAVE_ALPHASORT''@|$(HAVE_ALPHASORT)|g' \ -e 's|@''REPLACE_OPENDIR''@|$(REPLACE_OPENDIR)|g' \ + -e 's|@''REPLACE_READDIR''@|$(REPLACE_READDIR)|g' \ + -e 's|@''REPLACE_REWINDDIR''@|$(REPLACE_REWINDDIR)|g' \ -e 's|@''REPLACE_CLOSEDIR''@|$(REPLACE_CLOSEDIR)|g' \ -e 's|@''REPLACE_DIRFD''@|$(REPLACE_DIRFD)|g' \ -e 's|@''REPLACE_FDOPENDIR''@|$(REPLACE_FDOPENDIR)|g' \ diff --git a/modules/dirfd b/modules/dirfd index 0ffcf7ebbd..a87fa8b2e7 100644 --- a/modules/dirfd +++ b/modules/dirfd @@ -3,17 +3,18 @@ Retrieving the file descriptor of an open directory stream. (Unportable.) Files: lib/dirfd.c +lib/dirent-private.h m4/dirfd.m4 Depends-on: dirent extensions -errno [test $ac_cv_func_dirfd = no && test $gl_cv_func_dirfd_macro = no || test $REPLACE_DIRFD = 1] +errno [test $HAVE_DIRFD = 0 || test $REPLACE_DIRFD = 1] configure.ac: gl_FUNC_DIRFD gl_CONDITIONAL([GL_COND_OBJ_DIRFD], - [test $ac_cv_func_dirfd = no && test $gl_cv_func_dirfd_macro = no || test $REPLACE_DIRFD = 1]) + [test $HAVE_DIRFD = 0 || test $REPLACE_DIRFD = 1]) AM_COND_IF([GL_COND_OBJ_DIRFD], [ gl_PREREQ_DIRFD ]) diff --git a/modules/fdopendir b/modules/fdopendir index 2dec790167..7412254b6e 100644 --- a/modules/fdopendir +++ b/modules/fdopendir @@ -3,6 +3,7 @@ Open a directory stream from a file descriptor. Files: lib/fdopendir.c +lib/dirent-private.h m4/fdopendir.m4 Depends-on: diff --git a/modules/readdir b/modules/readdir index cfa61c9c64..111fd307af 100644 --- a/modules/readdir +++ b/modules/readdir @@ -12,7 +12,8 @@ largefile configure.ac: gl_FUNC_READDIR -gl_CONDITIONAL([GL_COND_OBJ_READDIR], [test $HAVE_READDIR = 0]) +gl_CONDITIONAL([GL_COND_OBJ_READDIR], + [test $HAVE_READDIR = 0 || test $REPLACE_READDIR = 1]) gl_DIRENT_MODULE_INDICATOR([readdir]) Makefile.am: diff --git a/modules/rewinddir b/modules/rewinddir index 38cf6db0bc..e4ccd2a6a5 100644 --- a/modules/rewinddir +++ b/modules/rewinddir @@ -13,7 +13,8 @@ largefile configure.ac: gl_FUNC_REWINDDIR -gl_CONDITIONAL([GL_COND_OBJ_REWINDDIR], [test $HAVE_REWINDDIR = 0]) +gl_CONDITIONAL([GL_COND_OBJ_REWINDDIR], + [test $HAVE_REWINDDIR = 0 || test $REPLACE_REWINDDIR = 1]) gl_DIRENT_MODULE_INDICATOR([rewinddir]) Makefile.am: |