From 75d6952a6726fce261a1757825fb0491fa195acf Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Tue, 26 Jul 2011 00:37:05 +0200
Subject: [PATCH] fcntl: Remove call-in from fchdir.m4.

* m4/fcntl.m4 (gl_FUNC_FCNTL): Conditionally invoke gl_TEST_FCHDIR.
* m4/fchdir.m4 (gl_FUNC_FCHDIR): Don't invoke gl_REPLACE_FCNTL.
---
 ChangeLog    |  4 ++++
 m4/fchdir.m4 |  1 -
 m4/fcntl.m4  | 10 +++++++++-
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ed1c1f713b..f776929166 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2011-07-25  Bruno Haible  <bruno@clisp.org>
 
+	fcntl: Remove call-in from fchdir.m4.
+	* m4/fcntl.m4 (gl_FUNC_FCNTL): Conditionally invoke gl_TEST_FCHDIR.
+	* m4/fchdir.m4 (gl_FUNC_FCHDIR): Don't invoke gl_REPLACE_FCNTL.
+
 	dup3: Remove potential call-in from fchdir.m4.
 	* m4/dup3.m4 (gl_FUNC_DUP3): Add comment about fchdir.
 	* m4/fchdir.m4 (gl_FUNC_FCHDIR): Remove comment about dup3.
diff --git a/m4/fchdir.m4 b/m4/fchdir.m4
index 502f62e9e4..a387dbb4f9 100644
--- a/m4/fchdir.m4
+++ b/m4/fchdir.m4
@@ -27,7 +27,6 @@ AC_DEFUN([gl_FUNC_FCHDIR],
     REPLACE_OPENDIR=1
     REPLACE_CLOSEDIR=1
     REPLACE_DUP=1
-    gl_REPLACE_FCNTL
     AC_CACHE_CHECK([whether open can visit directories],
       [gl_cv_func_open_directory_works],
       [AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <fcntl.h>
diff --git a/m4/fcntl.m4 b/m4/fcntl.m4
index a93ed85a36..19704465c1 100644
--- a/m4/fcntl.m4
+++ b/m4/fcntl.m4
@@ -1,4 +1,4 @@
-# fcntl.m4 serial 4
+# fcntl.m4 serial 5
 dnl Copyright (C) 2009-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -73,6 +73,14 @@ choke me
       dnl No witness macro needed for this bug.
     fi
   fi
+  dnl Replace fcntl() for supporting the gnulib-defined fchdir() function,
+  dnl to keep fchdir's bookkeeping up-to-date.
+  m4_ifdef([gl_FUNC_FCHDIR], [
+    gl_TEST_FCHDIR
+    if test $HAVE_FCHDIR = 0; then
+      gl_REPLACE_FCNTL
+    fi
+  ])
 ])
 
 AC_DEFUN([gl_REPLACE_FCNTL],
-- 
2.30.2