Override fopen more carefully.
authorBruno Haible <bruno@clisp.org>
Sun, 28 Sep 2008 14:12:20 +0000 (16:12 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 28 Sep 2008 14:12:20 +0000 (16:12 +0200)
ChangeLog
lib/fopen.c
m4/fopen.m4

index c301503c62bdc5534532529ba9b52950c6fe2e13..56bc03067c86d834a65e3f1218655125975c29ad 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-09-28  Bruno Haible  <bruno@clisp.org>
+
+       Override fopen more carefully.
+       * lib/fopen.c (orig_fopen): New function.
+       (rpl_fopen): Use orig_fopen instead of open.
+       * m4/fopen.m4 (gl_PREREQ_FOPEN): New macro.
+       (gl_FUNC_FOPEN): Invoke it.
+       Needed on AIX. Reported by Rainer Tammer <tammer@tammer.net>.
+
 2008-09-28  Bruno Haible  <bruno@clisp.org>
 
        * lib/pipe.h (create_pipe_out, create_pipe_bidi): Add comment about
index d6e048b79b6b43fa90ded109811a95926be9a740..b20d3bcd5a3b01bb824573e2aa7fa356a79a16cb 100644 (file)
 
 #include <config.h>
 
+/* Get the original definition of fopen.  It might be defined as a macro.  */
+#define __need_FILE
+#include <stdio.h>
+#undef __need_FILE
+
+static inline FILE *
+orig_fopen (const char *filename, const char *mode)
+{
+  return fopen (filename, mode);
+}
+
 /* Specification.  */
 #include <stdio.h>
 
@@ -28,7 +39,6 @@
 
 FILE *
 rpl_fopen (const char *filename, const char *mode)
-#undef fopen
 {
 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
   if (strcmp (filename, "/dev/null") == 0)
@@ -89,5 +99,5 @@ rpl_fopen (const char *filename, const char *mode)
   }
 # endif
 
-  return fopen (filename, mode);
+  return orig_fopen (filename, mode);
 }
index c1bbe8842128286c9316667625455db3710f709f..8f81a4a2440e6e4c647b9b59e8168b405079ad88 100644 (file)
@@ -1,4 +1,4 @@
-# fopen.m4 serial 2
+# fopen.m4 serial 3
 dnl Copyright (C) 2007-2008 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -43,8 +43,15 @@ changequote([,])dnl
             [Define to 1 if fopen() fails to recognize a trailing slash.])
           REPLACE_FOPEN=1
           AC_LIBOBJ([fopen])
+          gl_PREREQ_FOPEN
           ;;
       esac
       ;;
   esac
 ])
+
+# Prerequisites of lib/fopen.c.
+AC_DEFUN([gl_PREREQ_FOPEN],
+[
+  AC_REQUIRE([AC_C_INLINE])
+])