2008-09-28 Bruno Haible <bruno@clisp.org>
+ Override open more carefully.
+ * lib/open.c (orig_open): New function.
+ (rpl_open): Use orig_open instead of open.
+ * lib/fcntl.in.h: Add special invocation convention.
+ * m4/open.m4 (gl_PREREQ_OPEN): New macro.
+ (gl_FUNC_OPEN): Invoke it.
+
Override freopen more carefully.
* lib/freopen.c (orig_freopen): New function.
(rpl_freopen): Use orig_freopen instead of freopen.
/* written by Paul Eggert */
-#ifndef _GL_FCNTL_H
-
@PRAGMA_SYSTEM_HEADER@
+#if defined __need_system_fcntl_h
+/* Special invocation convention. */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#@INCLUDE_NEXT@ @NEXT_FCNTL_H@
+
+#else
+/* Normal invocation convention. */
+
+#ifndef _GL_FCNTL_H
+
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#endif /* _GL_FCNTL_H */
#endif /* _GL_FCNTL_H */
+#endif
#include <config.h>
+/* Get the original definition of open. It might be defined as a macro. */
+#define __need_system_fcntl_h
+#include <fcntl.h>
+#undef __need_system_fcntl_h
+#include <sys/types.h>
+
+static inline int
+orig_open (const char *filename, int flags, mode_t mode)
+{
+ return open (filename, flags, mode);
+}
+
/* Specification. */
#include <fcntl.h>
int
open (const char *filename, int flags, ...)
-# undef open
{
mode_t mode;
int fd;
}
# endif
- fd = open (filename, flags, mode);
+ fd = orig_open (filename, flags, mode);
# if OPEN_TRAILING_SLASH_BUG
/* If the filename ends in a slash and fd does not refer to a directory,
-# open.m4 serial 2
+# open.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,
[Define to 1 if open() fails to recognize a trailing slash.])
REPLACE_OPEN=1
AC_LIBOBJ([open])
+ gl_PREREQ_OPEN
;;
esac
;;
esac
])
+
+# Prerequisites of lib/open.c.
+AC_DEFUN([gl_PREREQ_OPEN],
+[
+ AC_REQUIRE([AC_C_INLINE])
+])