fchdir: improve use of replacement functions
authorEric Blake <ebb9@byu.net>
Tue, 15 Sep 2009 21:54:43 +0000 (15:54 -0600)
committerEric Blake <ebb9@byu.net>
Wed, 16 Sep 2009 03:46:51 +0000 (21:46 -0600)
* 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 <ebb9@byu.net>
ChangeLog
lib/dirent.in.h
lib/sys_stat.in.h
lib/unistd.in.h
m4/dirent_h.m4
m4/fchdir.m4
m4/sys_stat_h.m4
m4/unistd_h.m4
modules/dirent
modules/sys_stat
modules/unistd

index 322aca5..e58b782 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2009-09-15  Eric Blake  <ebb9@byu.net>
 
+       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.
 
index 8930765..6da77d9 100644 (file)
@@ -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,
index b0ea92d..869cb0f 100644 (file)
@@ -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
index f191412..553fb06 100644 (file)
@@ -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);
    <http://www.opengroup.org/susv3xsh/fchdir.html>.  */
 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);
index 06fffef..16d8a02 100644 (file)
@@ -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])
 ])
index 6597be0..f0e4dc0 100644 (file)
@@ -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
index 8b62902..4c01807 100644 (file)
@@ -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])
index 7347e38..e83dad3 100644 (file)
@@ -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])
index 3eb7411..454ac48 100644 (file)
@@ -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 && \
index 93bc70a..0747c4f 100644 (file)
@@ -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' \
index 37ecaaa..6bf5338 100644 (file)
@@ -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' \