+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.
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(). */
-# 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,
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
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
])