Eric Blake wrote: > ... a link failure on rpl_fstat. > ... > * lib/fchdir.c (rpl_fstat): Always provide if fchdir replacement > is in use.
If !REPLACE_OPEN_DIRECTORY the rpl_fstat does nothing else than to call fstat. We don't need rpl_fstat in this case. I'm applying this optimization. I've verified that it fixes the link failure. 2009-12-09 Bruno Haible <br...@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. --- lib/fchdir.c.orig 2009-12-09 12:00:04.000000000 +0100 +++ lib/fchdir.c 2009-12-09 11:52:53.000000000 +0100 @@ -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(). */ --- m4/fchdir.m4.orig 2009-12-09 12:00:04.000000000 +0100 +++ m4/fchdir.m4 2009-12-09 11:57:51.000000000 +0100 @@ -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 ])