changeset 12409:24c5ce8d8a76

fchdir: Optimize away rpl_fstat when possible.
author Bruno Haible <bruno@clisp.org>
date Wed, 09 Dec 2009 12:11:36 +0100
parents fd8770b153db
children 481fcf53f002
files ChangeLog lib/fchdir.c m4/fchdir.m4
diffstat 3 files changed, 13 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+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.
--- a/lib/fchdir.c
+++ b/lib/fchdir.c
@@ -216,18 +216,19 @@
   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().  */
--- a/m4/fchdir.m4
+++ b/m4/fchdir.m4
@@ -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 @@
     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 @@
     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
 ])