fchdir: Optimize away rpl_fstat when possible.
authorBruno Haible <bruno@clisp.org>
Wed, 9 Dec 2009 11:11:36 +0000 (12:11 +0100)
committerBruno Haible <bruno@clisp.org>
Wed, 9 Dec 2009 11:11:36 +0000 (12:11 +0100)
ChangeLog
lib/fchdir.c
m4/fchdir.m4

index bb6f984..7bfe2cd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2009-12-09  Bruno Haible  <bruno@clisp.org>
 
+       fchdir: Optimize away rpl_fstat when possible.
+       * m4/fchdir.m4 (gl_FUNC_FCHDIR): Set REPLACE_FSTAT only together with
+       REPLACE_OPEN_DIRECTORY.
+       * lib/fchdir.c (rpl_fstat): Define only when REPLACE_OPEN_DIRECTORY.
+
+2009-12-09  Bruno Haible  <bruno@clisp.org>
+
        * lib/fchdir.c: Update comment.
 
 2009-12-09  Bruno Haible  <bruno@clisp.org>
index 714e50d..5930940 100644 (file)
@@ -216,18 +216,19 @@ _gl_directory_name (int fd)
   return NULL;
 }
 
+#if REPLACE_OPEN_DIRECTORY
 /* Return stat information about FD in STATBUF.  Needed when
    rpl_open() used a dummy file to work around an open() that can't
    normally visit directories.  */
-#undef fstat
+# undef fstat
 int
 rpl_fstat (int fd, struct stat *statbuf)
 {
-  if (REPLACE_OPEN_DIRECTORY
-      && 0 <= fd && fd < dirs_allocated && dirs[fd].name != NULL)
+  if (0 <= fd && fd < dirs_allocated && dirs[fd].name != NULL)
     return stat (dirs[fd].name, statbuf);
   return fstat (fd, statbuf);
 }
+#endif
 
 /* Override opendir() and closedir(), to keep track of the open file
    descriptors.  Needed because there is a function dirfd().  */
index 6243cc2..e0240a1 100644 (file)
@@ -1,4 +1,4 @@
-# fchdir.m4 serial 11
+# fchdir.m4 serial 12
 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,
@@ -19,7 +19,6 @@ AC_DEFUN([gl_FUNC_FCHDIR],
     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
@@ -38,6 +37,7 @@ AC_DEFUN([gl_FUNC_FCHDIR],
     if test "$gl_cv_func_open_directory_works" != yes; then
       AC_DEFINE([REPLACE_OPEN_DIRECTORY], [1], [Define to 1 if open() should
 work around the inability to open a directory.])
+      REPLACE_FSTAT=1
     fi
   fi
 ])