* lib/closedir.c (closedir): Use Windows code path. * lib/dirent.in.h (_gl_register_dirp_fd, _gl_unregister_dirp_fd): Remove. * lib/dirfd.c (_gl_register_dirp_fd, _gl_unregister_dirp_fd): Remove. (dirfd): Use Windows code path. * lib/fdopendir.c (fdopendir): Use Windows code path. * lib/opendir.c (opendir): Use Windows code path. * m4/closedir.m4 (REPLACE_CLOSEDIR): Use Windows code path. * m4/dirent_h.m4 (DIR_HAS_FD_MEMBER): Use Windows code path. * m4/dirfd.m4 (REPLACE_DIRFD): Use Windows code path. * m4/fchdir.m4 (HAVE_FCHDIR): Replace fchdir() if dirfd() does not work. * m4/opendir.m4 (REPLACE_OPENDIR): Use Windows code path. * m4/readdir.m4 (REPLACE_READDIR): Use Windows code path. * m4/rewinddir.m4 (REPLACE_REWINDDIR): Use Windows code path. * modules/fchdir (Depends-on): Include dirent always. --- lib/closedir.c | 6 +---- lib/dirent.in.h | 6 ----- lib/dirfd.c | 65 ------------------------------------------------- lib/fdopendir.c | 36 --------------------------- lib/opendir.c | 22 ----------------- m4/closedir.m4 | 9 +++---- m4/dirent_h.m4 | 9 +++---- m4/dirfd.m4 | 9 +++---- m4/fchdir.m4 | 10 +++++++- m4/opendir.m4 | 10 +++----- m4/readdir.m4 | 5 ++-- m4/rewinddir.m4 | 5 ++-- modules/fchdir | 2 +- 13 files changed, 30 insertions(+), 164 deletions(-)
diff --git a/lib/closedir.c b/lib/closedir.c index 3777e9f70d..81f3babfcd 100644 --- a/lib/closedir.c +++ b/lib/closedir.c @@ -40,7 +40,7 @@ int closedir (DIR *dirp) #undef closedir { -#if GNULIB_defined_DIR || REPLACE_FCHDIR || defined __KLIBC__ +#if GNULIB_defined_DIR || REPLACE_FCHDIR int fd = dirfd (dirp); #endif int retval; @@ -55,10 +55,6 @@ closedir (DIR *dirp) retval = closedir (dirp); # endif -# ifdef __KLIBC__ - if (!retval) - _gl_unregister_dirp_fd (fd); -# endif #else if (dirp->current != INVALID_HANDLE_VALUE) diff --git a/lib/dirent.in.h b/lib/dirent.in.h index d409a031ec..2f5d3e3da8 100644 --- a/lib/dirent.in.h +++ b/lib/dirent.in.h @@ -237,12 +237,6 @@ _GL_WARN_ON_USE (rewinddir, "rewinddir is not portable - " _GL_FUNCDECL_RPL (dirfd, int, (DIR *) _GL_ARG_NONNULL ((1))); _GL_CXXALIAS_RPL (dirfd, int, (DIR *)); -# ifdef __KLIBC__ -/* Gnulib internal hooks needed to maintain the dirfd metadata. */ -_GL_EXTERN_C int _gl_register_dirp_fd (int fd, DIR *dirp) - _GL_ARG_NONNULL ((2)); -_GL_EXTERN_C void _gl_unregister_dirp_fd (int fd); -# endif # else # if defined __cplusplus && defined GNULIB_NAMESPACE && defined dirfd /* dirfd is defined as a macro and not as a function. diff --git a/lib/dirfd.c b/lib/dirfd.c index 75b2163c35..917fbeaba6 100644 --- a/lib/dirfd.c +++ b/lib/dirfd.c @@ -26,59 +26,6 @@ # include "dirent-private.h" #endif -#ifdef __KLIBC__ -# include <stdlib.h> -# include <io.h> - -static struct dirp_fd_list -{ - DIR *dirp; - int fd; - struct dirp_fd_list *next; -} *dirp_fd_start = NULL; - -/* Register fd associated with dirp to dirp_fd_list. */ -int -_gl_register_dirp_fd (int fd, DIR *dirp) -{ - struct dirp_fd_list *new_dirp_fd = malloc (sizeof *new_dirp_fd); - if (!new_dirp_fd) - return -1; - - new_dirp_fd->dirp = dirp; - new_dirp_fd->fd = fd; - new_dirp_fd->next = dirp_fd_start; - - dirp_fd_start = new_dirp_fd; - - return 0; -} - -/* Unregister fd from dirp_fd_list with closing it */ -void -_gl_unregister_dirp_fd (int fd) -{ - struct dirp_fd_list *dirp_fd; - struct dirp_fd_list *dirp_fd_prev; - - for (dirp_fd_prev = NULL, dirp_fd = dirp_fd_start; dirp_fd; - dirp_fd_prev = dirp_fd, dirp_fd = dirp_fd->next) - { - if (dirp_fd->fd == fd) - { - if (dirp_fd_prev) - dirp_fd_prev->next = dirp_fd->next; - else /* dirp_fd == dirp_fd_start */ - dirp_fd_start = dirp_fd_start->next; - - close (fd); - free (dirp_fd); - break; - } - } -} -#endif - int dirfd (DIR *dir_p) { @@ -90,19 +37,7 @@ dirfd (DIR *dir_p) #else int fd = DIR_TO_FD (dir_p); if (fd == -1) -# ifndef __KLIBC__ errno = ENOTSUP; -# else - { - struct dirp_fd_list *dirp_fd; - - for (dirp_fd = dirp_fd_start; dirp_fd; dirp_fd = dirp_fd->next) - if (dirp_fd->dirp == dir_p) - return dirp_fd->fd; - - errno = EINVAL; - } -# endif return fd; #endif diff --git a/lib/fdopendir.c b/lib/fdopendir.c index 0f43d6ff34..dd2f2aa73f 100644 --- a/lib/fdopendir.c +++ b/lib/fdopendir.c @@ -44,42 +44,6 @@ fdopendir (int fd) return dirp; } -# elif defined __KLIBC__ - -# include <InnoTekLIBC/backend.h> - -DIR * -fdopendir (int fd) -{ - char path[_MAX_PATH]; - DIR *dirp; - - /* Get a path from fd */ - if (__libc_Back_ioFHToPath (fd, path, sizeof (path))) - return NULL; - - dirp = opendir (path); - if (!dirp) - return NULL; - - /* Unregister fd registered by opendir() */ - _gl_unregister_dirp_fd (dirfd (dirp)); - - /* Register our fd */ - if (_gl_register_dirp_fd (fd, dirp)) - { - int saved_errno = errno; - - closedir (dirp); - - errno = saved_errno; - - dirp = NULL; - } - - return dirp; -} - # else /* We are not in control of the file descriptor of a DIR, and therefore have to play tricks with file descriptors before and after a call to opendir(). */ diff --git a/lib/opendir.c b/lib/opendir.c index ceb0e2829f..dad209bcb7 100644 --- a/lib/opendir.c +++ b/lib/opendir.c @@ -44,11 +44,6 @@ # include <unistd.h> #endif -#ifdef __KLIBC__ -# include <io.h> -# include <fcntl.h> -#endif - #if defined _WIN32 && ! defined __CYGWIN__ /* Don't assume that UNICODE is not defined. */ # undef WIN32_FIND_DATA @@ -93,23 +88,6 @@ opendir (const char *dir_name) return NULL; # endif -# ifdef __KLIBC__ - { - int fd = open (dir_name, O_RDONLY); - if (fd == -1 || _gl_register_dirp_fd (fd, dirp)) - { - int saved_errno = errno; - - close (fd); - closedir (dirp); - - errno = saved_errno; - - return NULL; - } - } -# endif - #else char dir_name_mask[MAX_PATH + 1 + 1 + 1]; diff --git a/m4/closedir.m4 b/m4/closedir.m4 index 7e702def25..ba77c19043 100644 --- a/m4/closedir.m4 +++ b/m4/closedir.m4 @@ -1,4 +1,4 @@ -# closedir.m4 serial 7 +# closedir.m4 serial 8 dnl Copyright (C) 2011-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -13,15 +13,12 @@ AC_DEFUN([gl_FUNC_CLOSEDIR], if test $ac_cv_func_closedir = no; then HAVE_CLOSEDIR=0 else - dnl Replace closedir() on native Windows, to support fdopendir(). + dnl Replace closedir() on native Windows and OS/2 kLIBC, + dnl to support fdopendir(). AC_REQUIRE([gl_DIRENT_DIR]) if test $DIR_HAS_FD_MEMBER = 0; then REPLACE_CLOSEDIR=1 fi - dnl Replace closedir() for supporting the gnulib-defined dirfd() function. - case $host_os in - os2*) REPLACE_CLOSEDIR=1 ;; - esac dnl Replace closedir() for supporting the gnulib-defined fchdir() function, dnl to keep fchdir's bookkeeping up-to-date. m4_ifdef([gl_FUNC_FCHDIR], [ diff --git a/m4/dirent_h.m4 b/m4/dirent_h.m4 index 922dd77862..5bc5f06050 100644 --- a/m4/dirent_h.m4 +++ b/m4/dirent_h.m4 @@ -1,4 +1,4 @@ -# dirent_h.m4 serial 21 +# dirent_h.m4 serial 22 dnl Copyright (C) 2008-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -32,14 +32,13 @@ AC_DEFUN_ONCE([gl_DIRENT_H], dnl Determine whether <dirent.h> needs to override the DIR type. AC_DEFUN_ONCE([gl_DIRENT_DIR], [ - dnl Set DIR_HAS_FD_MEMBER if dirfd() works, i.e. not always returns -1, - dnl or has the __KLIBC__ workaround as in lib/dirfd.c. + dnl Set DIR_HAS_FD_MEMBER if dirfd() works, i.e. not always returns -1. dnl We could use the findings from gl_FUNC_DIRFD and gl_PREREQ_DIRFD, but dnl it's simpler since we know the affected platforms. AC_REQUIRE([AC_CANONICAL_HOST]) case "$host_os" in - mingw* | windows*) DIR_HAS_FD_MEMBER=0 ;; - *) DIR_HAS_FD_MEMBER=1 ;; + mingw* | windows* | os2*) DIR_HAS_FD_MEMBER=0 ;; + *) DIR_HAS_FD_MEMBER=1 ;; esac AC_SUBST([DIR_HAS_FD_MEMBER]) ]) diff --git a/m4/dirfd.m4 b/m4/dirfd.m4 index 7968b1287c..61fe17d44d 100644 --- a/m4/dirfd.m4 +++ b/m4/dirfd.m4 @@ -1,4 +1,4 @@ -# serial 28 -*- Autoconf -*- +# serial 29 -*- Autoconf -*- dnl Find out how to get the file descriptor associated with an open DIR*. @@ -40,15 +40,12 @@ AC_DEFUN([gl_FUNC_DIRFD], HAVE_DIRFD=0 else HAVE_DIRFD=1 - dnl Replace dirfd() on native Windows, to support fdopendir(). + dnl Replace dirfd() on native Windows and OS/2 kLIBC, + dnl to support fdopendir(). AC_REQUIRE([gl_DIRENT_DIR]) if test $DIR_HAS_FD_MEMBER = 0; then REPLACE_DIRFD=1 fi - dnl OS/2 kLIBC dirfd() does not work. - case "$host_os" in - os2*) REPLACE_DIRFD=1 ;; - esac fi ]) diff --git a/m4/fchdir.m4 b/m4/fchdir.m4 index 72206baf98..49d37b5641 100644 --- a/m4/fchdir.m4 +++ b/m4/fchdir.m4 @@ -1,4 +1,4 @@ -# fchdir.m4 serial 29 +# fchdir.m4 serial 30 dnl Copyright (C) 2006-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -16,6 +16,14 @@ AC_DEFUN([gl_FUNC_FCHDIR], fi AC_REQUIRE([gl_TEST_FCHDIR]) + if test $HAVE_FCHDIR = 1; then + AC_REQUIRE([gl_DIRENT_DIR]) + if test $DIR_HAS_FD_MEMBER = 0; then + dnl fchdir() should be replaced if dirfd() does not work. + HAVE_FCHDIR=0 + fi + fi + if test $HAVE_FCHDIR = 0; then AC_DEFINE([REPLACE_FCHDIR], [1], [Define to 1 if gnulib's fchdir() replacement is used.]) diff --git a/m4/opendir.m4 b/m4/opendir.m4 index 2e9be769b5..3c9b25b320 100644 --- a/m4/opendir.m4 +++ b/m4/opendir.m4 @@ -1,4 +1,4 @@ -# opendir.m4 serial 6 +# opendir.m4 serial 7 dnl Copyright (C) 2011-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -13,16 +13,12 @@ AC_DEFUN([gl_FUNC_OPENDIR], if test $ac_cv_func_opendir = no; then HAVE_OPENDIR=0 else - dnl Replace opendir() on native Windows, to support fdopendir(). + dnl Replace opendir() on native Windows and OS/2 kLIBC, + dnl to support fdopendir(). AC_REQUIRE([gl_DIRENT_DIR]) if test $DIR_HAS_FD_MEMBER = 0; then REPLACE_OPENDIR=1 fi - dnl Replace opendir() on OS/2 kLIBC to support dirfd() function replaced - dnl by gnulib. - case $host_os in - os2*) REPLACE_OPENDIR=1 ;; - esac dnl Replace opendir() for supporting the gnulib-defined fchdir() function, dnl to keep fchdir's bookkeeping up-to-date. m4_ifdef([gl_FUNC_FCHDIR], [ diff --git a/m4/readdir.m4 b/m4/readdir.m4 index 81337e2ffa..e8cf5971df 100644 --- a/m4/readdir.m4 +++ b/m4/readdir.m4 @@ -1,4 +1,4 @@ -# readdir.m4 serial 2 +# readdir.m4 serial 3 dnl Copyright (C) 2011-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -12,7 +12,8 @@ AC_DEFUN([gl_FUNC_READDIR], if test $ac_cv_func_readdir = no; then HAVE_READDIR=0 else - dnl Replace readdir() on native Windows, to support fdopendir(). + dnl Replace readdir() on native Windows and OS/2 kLIBC, + dnl to support fdopendir(). AC_REQUIRE([gl_DIRENT_DIR]) if test $DIR_HAS_FD_MEMBER = 0; then REPLACE_READDIR=1 diff --git a/m4/rewinddir.m4 b/m4/rewinddir.m4 index d0d24de8a6..7a4d0c8190 100644 --- a/m4/rewinddir.m4 +++ b/m4/rewinddir.m4 @@ -1,4 +1,4 @@ -# rewinddir.m4 serial 2 +# rewinddir.m4 serial 3 dnl Copyright (C) 2011-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -12,7 +12,8 @@ AC_DEFUN([gl_FUNC_REWINDDIR], if test $ac_cv_func_rewinddir = no; then HAVE_REWINDDIR=0 else - dnl Replace rewinddir() on native Windows, to support fdopendir(). + dnl Replace rewinddir() on native Windows and OS/2 kLIBC, + dnl to support fdopendir(). AC_REQUIRE([gl_DIRENT_DIR]) if test $DIR_HAS_FD_MEMBER = 0; then REPLACE_REWINDDIR=1 diff --git a/modules/fchdir b/modules/fchdir index 13437a92f1..847624a548 100644 --- a/modules/fchdir +++ b/modules/fchdir @@ -6,11 +6,11 @@ lib/fchdir.c m4/fchdir.m4 Depends-on: +dirent unistd assure [test $HAVE_FCHDIR = 0] chdir [test $HAVE_FCHDIR = 0] close [test $HAVE_FCHDIR = 0] -dirent [test $HAVE_FCHDIR = 0] dirfd [test $HAVE_FCHDIR = 0] dup2 [test $HAVE_FCHDIR = 0] fcntl [test $HAVE_FCHDIR = 0] -- 2.39.1