* 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.
+2023-09-29 KO Myung-Hun <komh78@gmail.com>
+
+ fdopendir: Use Windows code path on OS/2 kLIBC
+ * 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.
+
2023-09-26 Paul Eggert <eggert@cs.ucla.edu>
mcel-bench-tests: fix typo
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;
retval = closedir (dirp);
# endif
-# ifdef __KLIBC__
- if (!retval)
- _gl_unregister_dirp_fd (fd);
-# endif
#else
if (dirp->current != INVALID_HANDLE_VALUE)
_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.
# 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)
{
#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
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(). */
# 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
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];
-# 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,
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], [
-# 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,
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])
])
-# serial 28 -*- Autoconf -*-
+# serial 29 -*- Autoconf -*-
dnl Find out how to get the file descriptor associated with an open DIR*.
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
])
-# 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,
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.])
-# 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,
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], [
-# 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,
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
-# 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,
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
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]