From: Bruno Haible Date: Wed, 9 Dec 2009 11:11:36 +0000 (+0100) Subject: fchdir: Optimize away rpl_fstat when possible. X-Git-Tag: v0.1~5078 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=a226e8ae00484017b342f9299f9d3c88e413b827;p=gnulib.git fchdir: Optimize away rpl_fstat when possible. --- diff --git a/ChangeLog b/ChangeLog index bb6f9848b..7bfe2cd45 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2009-12-09 Bruno Haible + 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 + * lib/fchdir.c: Update comment. 2009-12-09 Bruno Haible diff --git a/lib/fchdir.c b/lib/fchdir.c index 714e50d13..5930940bd 100644 --- a/lib/fchdir.c +++ b/lib/fchdir.c @@ -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(). */ diff --git a/m4/fchdir.m4 b/m4/fchdir.m4 index 6243cc283..e0240a15f 100644 --- 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 @@ 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 ])