From: Bruno Haible Date: Sun, 28 Sep 2008 14:19:57 +0000 (+0200) Subject: Override open more carefully. X-Git-Tag: v0.1~6949 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=e2600ffdcf6c35561545d553e07e52e0db8f9a38;p=gnulib.git Override open more carefully. --- diff --git a/ChangeLog b/ChangeLog index 53789ebdc..d56488efa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2008-09-28 Bruno Haible + 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. diff --git a/lib/fcntl.in.h b/lib/fcntl.in.h index 278f2039f..79b8f165f 100644 --- a/lib/fcntl.in.h +++ b/lib/fcntl.in.h @@ -17,10 +17,21 @@ /* written by Paul Eggert */ -#ifndef _GL_FCNTL_H - @PRAGMA_SYSTEM_HEADER@ +#if defined __need_system_fcntl_h +/* Special invocation convention. */ + +#include +#include +#include +#@INCLUDE_NEXT@ @NEXT_FCNTL_H@ + +#else +/* Normal invocation convention. */ + +#ifndef _GL_FCNTL_H + #include #include #include @@ -121,3 +132,4 @@ extern int open (const char *filename, int flags, ...); #endif /* _GL_FCNTL_H */ #endif /* _GL_FCNTL_H */ +#endif diff --git a/lib/open.c b/lib/open.c index 97c30cee8..9a35f5b2a 100644 --- a/lib/open.c +++ b/lib/open.c @@ -18,6 +18,18 @@ #include +/* Get the original definition of open. It might be defined as a macro. */ +#define __need_system_fcntl_h +#include +#undef __need_system_fcntl_h +#include + +static inline int +orig_open (const char *filename, int flags, mode_t mode) +{ + return open (filename, flags, mode); +} + /* Specification. */ #include @@ -32,7 +44,6 @@ int open (const char *filename, int flags, ...) -# undef open { mode_t mode; int fd; @@ -91,7 +102,7 @@ open (const char *filename, int flags, ...) } # 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, diff --git a/m4/open.m4 b/m4/open.m4 index 335f4e500..fab0ad987 100644 --- a/m4/open.m4 +++ b/m4/open.m4 @@ -1,4 +1,4 @@ -# 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, @@ -45,8 +45,15 @@ changequote([,])dnl [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]) +])