KO Myung-Hun wrote: > * 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.
Thanks for the nice simplification. I'm applying it, together with this patch: 2023-09-29 Bruno Haible <br...@clisp.org> fchdir: Override properly on OS/2 kLIBC. * lib/unistd.in.h (fchdir): Override if REPLACE_FCHDIR is 1. * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize REPLACE_FCHDIR. * modules/unistd (Makefile.am): Substitute REPLACE_FCHDIR. * modules/fchdir (Depends-on, configure.ac): Test REPLACE_FCHDIR. * m4/fchdir.m4 (gl_FUNC_FCHDIR): Instead of setting HAVE_FCHDIR to 0, set REPLACE_FCHDIR to 1. diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 2ae040a76b..ac9f50eb3e 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -971,23 +971,28 @@ _GL_WARN_ON_USE (faccessat, "faccessat is not portable - " Return 0 if successful, otherwise -1 and errno set. See the POSIX:2008 specification <https://pubs.opengroup.org/onlinepubs/9699919799/functions/fchdir.html>. */ -# if ! @HAVE_FCHDIR@ +# if @REPLACE_FCHDIR@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fchdir +# define fchdir rpl_fchdir +# endif +_GL_FUNCDECL_RPL (fchdir, int, (int /*fd*/)); +_GL_CXXALIAS_RPL (fchdir, int, (int /*fd*/)); +# else +# if !@HAVE_FCHDIR@ || !@HAVE_DECL_FCHDIR@ _GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/)); - +# endif +_GL_CXXALIAS_SYS (fchdir, int, (int /*fd*/)); +# endif +_GL_CXXALIASWARN (fchdir); +# if @REPLACE_FCHDIR@ || !@HAVE_FCHDIR@ /* Gnulib internal hooks needed to maintain the fchdir metadata. */ _GL_EXTERN_C int _gl_register_fd (int fd, const char *filename) _GL_ARG_NONNULL ((2)); _GL_EXTERN_C void _gl_unregister_fd (int fd); _GL_EXTERN_C int _gl_register_dup (int oldfd, int newfd); _GL_EXTERN_C const char *_gl_directory_name (int fd); - -# else -# if !@HAVE_DECL_FCHDIR@ -_GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/)); -# endif # endif -_GL_CXXALIAS_SYS (fchdir, int, (int /*fd*/)); -_GL_CXXALIASWARN (fchdir); #elif defined GNULIB_POSIXCHECK # undef fchdir # if HAVE_RAW_DECL_FCHDIR diff --git a/m4/fchdir.m4 b/m4/fchdir.m4 index 49d37b5641..ff92ceca2e 100644 --- a/m4/fchdir.m4 +++ b/m4/fchdir.m4 @@ -1,4 +1,4 @@ -# fchdir.m4 serial 30 +# fchdir.m4 serial 31 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, @@ -20,7 +20,7 @@ AC_DEFUN([gl_FUNC_FCHDIR] 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 + REPLACE_FCHDIR=1 fi fi diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4 index 1c96158155..8fa0fa3255 100644 --- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -1,4 +1,4 @@ -# unistd_h.m4 serial 94 +# unistd_h.m4 serial 95 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, @@ -234,6 +234,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS] REPLACE_EXECVP=0; AC_SUBST([REPLACE_EXECVP]) REPLACE_EXECVPE=0; AC_SUBST([REPLACE_EXECVPE]) REPLACE_FACCESSAT=0; AC_SUBST([REPLACE_FACCESSAT]) + REPLACE_FCHDIR=0; AC_SUBST([REPLACE_FCHDIR]) REPLACE_FCHOWNAT=0; AC_SUBST([REPLACE_FCHOWNAT]) REPLACE_FDATASYNC=0; AC_SUBST([REPLACE_FDATASYNC]) REPLACE_FTRUNCATE=0; AC_SUBST([REPLACE_FTRUNCATE]) diff --git a/modules/fchdir b/modules/fchdir index 847624a548..084806941b 100644 --- a/modules/fchdir +++ b/modules/fchdir @@ -8,29 +8,30 @@ m4/fchdir.m4 Depends-on: dirent unistd -assure [test $HAVE_FCHDIR = 0] -chdir [test $HAVE_FCHDIR = 0] -close [test $HAVE_FCHDIR = 0] -dirfd [test $HAVE_FCHDIR = 0] -dup2 [test $HAVE_FCHDIR = 0] -fcntl [test $HAVE_FCHDIR = 0] -fcntl-h [test $HAVE_FCHDIR = 0] -filename [test $HAVE_FCHDIR = 0] -filenamecat-lgpl [test $HAVE_FCHDIR = 0] -free-posix [test $HAVE_FCHDIR = 0] -fstat [test $HAVE_FCHDIR = 0] -getcwd-lgpl [test $HAVE_FCHDIR = 0] -malloc-posix [test $HAVE_FCHDIR = 0] -open [test $HAVE_FCHDIR = 0] -realloc-posix [test $HAVE_FCHDIR = 0] -stat [test $HAVE_FCHDIR = 0] -stdbool [test $HAVE_FCHDIR = 0] -strdup-posix [test $HAVE_FCHDIR = 0] -sys_stat [test $HAVE_FCHDIR = 0] +assure [test $HAVE_FCHDIR = 0 || test $REPLACE_FCHDIR = 1] +chdir [test $HAVE_FCHDIR = 0 || test $REPLACE_FCHDIR = 1] +close [test $HAVE_FCHDIR = 0 || test $REPLACE_FCHDIR = 1] +dirfd [test $HAVE_FCHDIR = 0 || test $REPLACE_FCHDIR = 1] +dup2 [test $HAVE_FCHDIR = 0 || test $REPLACE_FCHDIR = 1] +fcntl [test $HAVE_FCHDIR = 0 || test $REPLACE_FCHDIR = 1] +fcntl-h [test $HAVE_FCHDIR = 0 || test $REPLACE_FCHDIR = 1] +filename [test $HAVE_FCHDIR = 0 || test $REPLACE_FCHDIR = 1] +filenamecat-lgpl [test $HAVE_FCHDIR = 0 || test $REPLACE_FCHDIR = 1] +free-posix [test $HAVE_FCHDIR = 0 || test $REPLACE_FCHDIR = 1] +fstat [test $HAVE_FCHDIR = 0 || test $REPLACE_FCHDIR = 1] +getcwd-lgpl [test $HAVE_FCHDIR = 0 || test $REPLACE_FCHDIR = 1] +malloc-posix [test $HAVE_FCHDIR = 0 || test $REPLACE_FCHDIR = 1] +open [test $HAVE_FCHDIR = 0 || test $REPLACE_FCHDIR = 1] +realloc-posix [test $HAVE_FCHDIR = 0 || test $REPLACE_FCHDIR = 1] +stat [test $HAVE_FCHDIR = 0 || test $REPLACE_FCHDIR = 1] +stdbool [test $HAVE_FCHDIR = 0 || test $REPLACE_FCHDIR = 1] +strdup-posix [test $HAVE_FCHDIR = 0 || test $REPLACE_FCHDIR = 1] +sys_stat [test $HAVE_FCHDIR = 0 || test $REPLACE_FCHDIR = 1] configure.ac: gl_FUNC_FCHDIR -gl_CONDITIONAL([GL_COND_OBJ_FCHDIR], [test $HAVE_FCHDIR = 0]) +gl_CONDITIONAL([GL_COND_OBJ_FCHDIR], + [test $HAVE_FCHDIR = 0 || test $REPLACE_FCHDIR = 1]) AM_COND_IF([GL_COND_OBJ_FCHDIR], [ gl_PREREQ_FCHDIR ]) diff --git a/modules/unistd b/modules/unistd index f244b0dd9a..ce2ee04edc 100644 --- a/modules/unistd +++ b/modules/unistd @@ -192,6 +192,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H -e 's|@''REPLACE_EXECVP''@|$(REPLACE_EXECVP)|g' \ -e 's|@''REPLACE_EXECVPE''@|$(REPLACE_EXECVPE)|g' \ -e 's|@''REPLACE_FACCESSAT''@|$(REPLACE_FACCESSAT)|g' \ + -e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \ -e 's|@''REPLACE_FCHOWNAT''@|$(REPLACE_FCHOWNAT)|g' \ -e 's|@''REPLACE_FDATASYNC''@|$(REPLACE_FDATASYNC)|g' \ -e 's|@''REPLACE_FTRUNCATE''@|$(REPLACE_FTRUNCATE)|g' \