bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

overriding fopen and open


From: Bruno Haible
Subject: overriding fopen and open
Date: Sun, 28 Sep 2008 16:15:53 +0200
User-agent: KMail/1.5.4

The fopen() override leads to a compilation error on AIX. What happens:
  - The system's <stdio.h> defines
      #define fopen fopen64
    before providing a declaration for fopen.
  - gnulib's fopen.c defines rpl_fopen() with an invocation to a #undef'ed
    fopen. But this has never been declared and therefore an assignment from
    its return value to 'FILE *' fails.

I'm applying this, and similarly for freopen() and open().


2008-09-28  Bruno Haible  <address@hidden>

        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 <address@hidden>.

--- lib/fopen.c.orig    2008-09-28 16:08:39.000000000 +0200
+++ lib/fopen.c 2008-09-28 15:16:35.000000000 +0200
@@ -18,6 +18,17 @@
 
 #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 @@
   }
 # endif
 
-  return fopen (filename, mode);
+  return orig_fopen (filename, mode);
 }
--- m4/fopen.m4.orig    2008-09-28 16:08:39.000000000 +0200
+++ m4/fopen.m4 2008-09-28 15:18:27.000000000 +0200
@@ -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 @@
             [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])
+])





reply via email to

[Prev in Thread] Current Thread [Next in Thread]