]> Savannah Git Hosting - gnulib.git/commitdiff
fdopendir: Use Windows code path on OS/2 kLIBC
authorKO Myung-Hun <komh78@gmail.com>
Mon, 25 Sep 2023 14:38:28 +0000 (23:38 +0900)
committerBruno Haible <bruno@clisp.org>
Fri, 29 Sep 2023 08:31:49 +0000 (10:31 +0200)
* 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.

14 files changed:
ChangeLog
lib/closedir.c
lib/dirent.in.h
lib/dirfd.c
lib/fdopendir.c
lib/opendir.c
m4/closedir.m4
m4/dirent_h.m4
m4/dirfd.m4
m4/fchdir.m4
m4/opendir.m4
m4/readdir.m4
m4/rewinddir.m4
modules/fchdir

index d514dddebab149c102a3c9bf7cae83a191fda1b6..f84e227f0b40918453a5604bd5be45360f7a3c1a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+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
index 3777e9f70d1c98f54b8299923c2c5c8dbc97917b..81f3babfcd11e06f8d962e0617508bf6139c7909 100644 (file)
@@ -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)
index d409a031ec815dbed9e42ec187c661db1d30d81e..2f5d3e3da82d8508c7553c9423a77f1388f5b5bb 100644 (file)
@@ -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.
index 75b2163c35378cc11b06d109d77ce219c0164cb2..917fbeaba6719736fb8b58ff47431c11e8b9ea4f 100644 (file)
 # 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
index 0f43d6ff349a5a01b735daec37056306ca70683f..dd2f2aa73f064d2efbfa5be035baa877d1bd6e06 100644 (file)
@@ -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().  */
index ceb0e2829fe70dcf5eb01a2b63126d0fd7f7eccd..dad209bcb72dae0fc9abbc3e279219bf748eec1a 100644 (file)
 # 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];
index 7e702def259c9e8f00f95e054ebb0df93dd5e753..ba77c19043e7c27c62db4f79a6baee1ebbc6bf1f 100644 (file)
@@ -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], [
index 922dd77862fbe9e84a2d52db2a4c12be5783dbc6..5bc5f060502c87a12395ebe2e50148efc2ab6bc6 100644 (file)
@@ -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])
 ])
index 7968b1287cef7cfa93923cdefb203ee3b814d41c..61fe17d44dcef818445861b1aee481b0f2bbaa00 100644 (file)
@@ -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
 ])
 
index 72206baf98ad433e30b7418711c000702765abfb..49d37b5641811285b6007c8f78bce778802c51b4 100644 (file)
@@ -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.])
index 2e9be769b534b0ead564c36ccafec5ec98678af5..3c9b25b3207d97768884efe4b804e0f0319c9d9b 100644 (file)
@@ -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], [
index 81337e2ffa25bb3a91a558bbf7fdf57a81b9c0b8..e8cf5971df695bbc820bb848d4a04e72e00e7499 100644 (file)
@@ -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
index d0d24de8a6f4401382b22c275db75f38fa4e6e28..7a4d0c8190e2e08f446c59dbb82d5ff1eef3814d 100644 (file)
@@ -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
index 13437a92f135c48298ed902a81924323499244bd..847624a54828b044e16a5793c7893c391ac66833 100644 (file)
@@ -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]