From c9dd0005fe00602d13c3d54f0834655b1e769520 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 15 Sep 2009 15:54:43 -0600 Subject: [PATCH] fchdir: improve use of replacement functions * m4/fchdir.m4 (gl_FUNC_FCHDIR): Set appropriate witnesses. * m4/sys_stat_h.m4 (gl_SYS_STAT_H_DEFAULTS): Add REPLACE_FSTAT. * m4/dirent_h.m4 (gl_DIRENT_H_DEFAULTS): Add REPLACE_OPENDIR, REPLACE_CLOSEDIR. * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Add REPLACE_DUP. * modules/sys_stat (Makefile.am): Substitute correct witness. * modules/dirent (Makefile.am): Likewise. * modules/unistd (Makefile.am): Likewise. * lib/dirent.in.h (opendir, closedir): Use better witnesses. * lib/unistd.in.h (dup): Likewise. * lib/sys_stat.in.h (fstat): Likewise. Signed-off-by: Eric Blake --- ChangeLog | 13 +++++++++++++ lib/dirent.in.h | 11 ++++++----- lib/sys_stat.in.h | 2 +- lib/unistd.in.h | 8 ++++---- m4/dirent_h.m4 | 4 +++- m4/fchdir.m4 | 8 +++++++- m4/sys_stat_h.m4 | 3 ++- m4/unistd_h.m4 | 3 ++- modules/dirent | 3 ++- modules/sys_stat | 2 +- modules/unistd | 1 + 11 files changed, 42 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 322aca52b..e58b7829a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2009-09-15 Eric Blake + fchdir: improve use of replacement functions + * m4/fchdir.m4 (gl_FUNC_FCHDIR): Set appropriate witnesses. + * m4/sys_stat_h.m4 (gl_SYS_STAT_H_DEFAULTS): Add REPLACE_FSTAT. + * m4/dirent_h.m4 (gl_DIRENT_H_DEFAULTS): Add REPLACE_OPENDIR, + REPLACE_CLOSEDIR. + * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Add REPLACE_DUP. + * modules/sys_stat (Makefile.am): Substitute correct witness. + * modules/dirent (Makefile.am): Likewise. + * modules/unistd (Makefile.am): Likewise. + * lib/dirent.in.h (opendir, closedir): Use better witnesses. + * lib/unistd.in.h (dup): Likewise. + * lib/sys_stat.in.h (fstat): Likewise. + maint: ignore gnulib-tool temp files * .gitignore: Ignore files created during gnulib-tool --test. diff --git a/lib/dirent.in.h b/lib/dirent.in.h index 893076567..6da77d9ff 100644 --- a/lib/dirent.in.h +++ b/lib/dirent.in.h @@ -35,15 +35,11 @@ extern "C" { /* Declare overridden functions. */ -#if @REPLACE_FCHDIR@ -# define opendir rpl_opendir -extern DIR * opendir (const char *); +#if @REPLACE_CLOSEDIR@ # define closedir rpl_closedir extern int closedir (DIR *); #endif -/* Declare other POSIX functions. */ - #if @GNULIB_DIRFD@ # if !@HAVE_DECL_DIRFD@ && !defined dirfd /* Return the file descriptor associated with the given directory stream, @@ -75,6 +71,11 @@ extern DIR *fdopendir (int fd); fdopendir (f)) #endif +#if @REPLACE_OPENDIR@ +# define opendir rpl_opendir +extern DIR * opendir (const char *); +#endif + #if @GNULIB_SCANDIR@ /* Scan the directory DIR, calling FILTER on each directory entry. Entries for which FILTER returns nonzero are individually malloc'd, diff --git a/lib/sys_stat.in.h b/lib/sys_stat.in.h index b0ea92d6e..869cb0f93 100644 --- a/lib/sys_stat.in.h +++ b/lib/sys_stat.in.h @@ -369,7 +369,7 @@ int mknodat (int fd, char const *file, mode_t mode, dev_t dev); mknodat (f, n, m, d)) #endif -#if @REPLACE_FCHDIR@ +#if @REPLACE_FSTAT@ # define fstat rpl_fstat extern int fstat (int fd, struct stat *buf); #endif diff --git a/lib/unistd.in.h b/lib/unistd.in.h index f191412e2..553fb06eb 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -231,6 +231,10 @@ extern int close (int); close (f)) #endif +#if @REPLACE_DUP@ +# define dup rpl_dup +extern int dup (int); +#endif #if @GNULIB_DUP2@ # if @REPLACE_DUP2@ @@ -312,7 +316,6 @@ extern int euidaccess (const char *filename, int mode); #if @GNULIB_FCHDIR@ # if @REPLACE_FCHDIR@ - /* Change the process' current working directory to the directory on which the given file descriptor is open. Return 0 if successful, otherwise -1 and errno set. @@ -320,9 +323,6 @@ extern int euidaccess (const char *filename, int mode); . */ extern int fchdir (int /*fd*/); -# define dup rpl_dup -extern int dup (int); - /* Gnulib internal hooks needed to maintain the fchdir metadata. */ extern int _gl_register_fd (int fd, const char *filename); extern void _gl_unregister_fd (int fd); diff --git a/m4/dirent_h.m4 b/m4/dirent_h.m4 index 06fffefc1..16d8a0221 100644 --- a/m4/dirent_h.m4 +++ b/m4/dirent_h.m4 @@ -1,4 +1,4 @@ -# dirent_h.m4 serial 4 +# dirent_h.m4 serial 5 dnl Copyright (C) 2008-2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -41,5 +41,7 @@ AC_DEFUN([gl_DIRENT_H_DEFAULTS], HAVE_FDOPENDIR=1; AC_SUBST([HAVE_FDOPENDIR]) HAVE_SCANDIR=1; AC_SUBST([HAVE_SCANDIR]) HAVE_ALPHASORT=1; AC_SUBST([HAVE_ALPHASORT]) + REPLACE_CLOSEDIR=0; AC_SUBST([REPLACE_CLOSEDIR]) + REPLACE_OPENDIR=0; AC_SUBST([REPLACE_OPENDIR]) DIRENT_H=''; AC_SUBST([DIRENT_H]) ]) diff --git a/m4/fchdir.m4 b/m4/fchdir.m4 index 6597be06c..f0e4dc00d 100644 --- a/m4/fchdir.m4 +++ b/m4/fchdir.m4 @@ -1,4 +1,4 @@ -# fchdir.m4 serial 9 +# fchdir.m4 serial 10 dnl Copyright (C) 2006-2009 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,7 +16,13 @@ AC_DEFUN([gl_FUNC_FCHDIR], gl_PREREQ_FCHDIR AC_DEFINE([REPLACE_FCHDIR], [1], [Define to 1 if gnulib's fchdir() replacement is used.]) + dnl We must also replace anything that can manipulate a directory fd, + dnl to keep our bookkeeping up-to-date. We don't have to replace + dnl fstatat, since no platform has fstatat but lacks fchdir. REPLACE_FSTAT=1 + REPLACE_OPENDIR=1 + REPLACE_CLOSEDIR=1 + REPLACE_DUP=1 gl_REPLACE_OPEN gl_REPLACE_CLOSE gl_REPLACE_DUP2 diff --git a/m4/sys_stat_h.m4 b/m4/sys_stat_h.m4 index 8b62902c5..4c01807b4 100644 --- a/m4/sys_stat_h.m4 +++ b/m4/sys_stat_h.m4 @@ -1,4 +1,4 @@ -# sys_stat_h.m4 serial 14 -*- Autoconf -*- +# sys_stat_h.m4 serial 15 -*- Autoconf -*- dnl Copyright (C) 2006-2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -63,6 +63,7 @@ AC_DEFUN([gl_SYS_STAT_H_DEFAULTS], HAVE_MKDIRAT=1; AC_SUBST([HAVE_MKDIRAT]) HAVE_MKFIFOAT=1; AC_SUBST([HAVE_MKFIFOAT]) HAVE_MKNODAT=1; AC_SUBST([HAVE_MKNODAT]) + REPLACE_FSTAT=0; AC_SUBST([REPLACE_FSTAT]) REPLACE_FSTATAT=0; AC_SUBST([REPLACE_FSTATAT]) REPLACE_LSTAT=0; AC_SUBST([REPLACE_LSTAT]) REPLACE_MKDIR=0; AC_SUBST([REPLACE_MKDIR]) diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4 index 7347e3877..e83dad393 100644 --- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -1,4 +1,4 @@ -# unistd_h.m4 serial 25 +# unistd_h.m4 serial 26 dnl Copyright (C) 2006-2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -88,6 +88,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], HAVE_UNLINKAT=1; AC_SUBST([HAVE_UNLINKAT]) REPLACE_CHOWN=0; AC_SUBST([REPLACE_CHOWN]) REPLACE_CLOSE=0; AC_SUBST([REPLACE_CLOSE]) + REPLACE_DUP=0; AC_SUBST([REPLACE_DUP]) REPLACE_DUP2=0; AC_SUBST([REPLACE_DUP2]) REPLACE_FCHDIR=0; AC_SUBST([REPLACE_FCHDIR]) REPLACE_FCHOWNAT=0; AC_SUBST([REPLACE_FCHOWNAT]) diff --git a/modules/dirent b/modules/dirent index 3eb7411f1..454ac48d4 100644 --- a/modules/dirent +++ b/modules/dirent @@ -32,7 +32,8 @@ dirent.h: dirent.in.h -e 's|@''HAVE_FDOPENDIR''@|$(HAVE_FDOPENDIR)|g' \ -e 's|@''HAVE_SCANDIR''@|$(HAVE_SCANDIR)|g' \ -e 's|@''HAVE_ALPHASORT''@|$(HAVE_ALPHASORT)|g' \ - -e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \ + -e 's|@''REPLACE_CLOSEDIR''@|$(REPLACE_CLOSEDIR)|g' \ + -e 's|@''REPLACE_OPENDIR''@|$(REPLACE_OPENDIR)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ < $(srcdir)/dirent.in.h; \ } > $@-t && \ diff --git a/modules/sys_stat b/modules/sys_stat index 93bc70a45..0747c4f71 100644 --- a/modules/sys_stat +++ b/modules/sys_stat @@ -40,7 +40,7 @@ sys/stat.h: sys_stat.in.h -e 's|@''HAVE_MKDIRAT''@|$(HAVE_MKDIRAT)|g' \ -e 's|@''HAVE_MKFIFOAT''@|$(HAVE_MKFIFOAT)|g' \ -e 's|@''HAVE_MKNODAT''@|$(HAVE_MKNODAT)|g' \ - -e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \ + -e 's|@''REPLACE_FSTAT''@|$(REPLACE_FSTAT)|g' \ -e 's|@''REPLACE_FSTATAT''@|$(REPLACE_FSTATAT)|g' \ -e 's|@''REPLACE_LSTAT''@|$(REPLACE_LSTAT)|g' \ -e 's|@''REPLACE_MKDIR''@|$(REPLACE_MKDIR)|g' \ diff --git a/modules/unistd b/modules/unistd index 37ecaaafc..6bf5338a9 100644 --- a/modules/unistd +++ b/modules/unistd @@ -80,6 +80,7 @@ unistd.h: unistd.in.h -e 's|@''HAVE_SYS_PARAM_H''@|$(HAVE_SYS_PARAM_H)|g' \ -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \ -e 's|@''REPLACE_CLOSE''@|$(REPLACE_CLOSE)|g' \ + -e 's|@''REPLACE_DUP''@|$(REPLACE_DUP)|g' \ -e 's|@''REPLACE_DUP2''@|$(REPLACE_DUP2)|g' \ -e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \ -e 's|@''REPLACE_FCHOWNAT''@|$(REPLACE_FCHOWNAT)|g' \ -- 2.11.0