From 7fe8aa4ab1b398dc20d6c35edb0aa4fc191363d9 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 8 Mar 2010 00:51:34 +0100 Subject: [PATCH] fcntl-h: Avoid #define replacements in C++ mode. --- ChangeLog | 6 +++++ lib/fcntl.in.h | 63 ++++++++++++++++++++++++++++++++----------------- modules/fcntl-h | 4 +++- 3 files changed, 51 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index eef8943250..c0470ab1a5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2010-03-07 Bruno Haible + fcntl-h: Avoid #define replacements in C++ mode. + * lib/fcntl.in.h: Include c++defs.h. + (fcntl, open, openat): In C++, define a namespaced alias symbol. + * modules/fcntl-h (Depends-on): Add c++defs. + (Makefile.am): Update fcntl.h rule. + dirent: Avoid #define replacements in C++ mode. * lib/dirent.in.h: Include c++defs.h. (closedir, fdopendir, opendir, scandir, alphasort): In C++, define a diff --git a/lib/fcntl.in.h b/lib/fcntl.in.h index a1d9e23087..8fb7852204 100644 --- a/lib/fcntl.in.h +++ b/lib/fcntl.in.h @@ -50,6 +50,8 @@ #endif +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + /* The definition of _GL_ARG_NONNULL is copied here. */ /* The definition of _GL_WARN_ON_USE is copied here. */ @@ -57,18 +59,21 @@ /* Declare overridden functions. */ -#ifdef __cplusplus -extern "C" { -#endif - #if @GNULIB_FCNTL@ # if @REPLACE_FCNTL@ -# undef fcntl -# define fcntl rpl_fcntl -# endif -# if !@HAVE_FCNTL@ || @REPLACE_FCNTL@ -extern int fcntl (int fd, int action, ...); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fcntl +# define fcntl rpl_fcntl +# endif +_GL_FUNCDECL_RPL (fcntl, int, (int fd, int action, ...)); +_GL_CXXALIAS_RPL (fcntl, int, (int fd, int action, ...)); +# else +# if !@HAVE_FCNTL@ +_GL_FUNCDECL_SYS (fcntl, int, (int fd, int action, ...)); +# endif +_GL_CXXALIAS_SYS (fcntl, int, (int fd, int action, ...)); # endif +_GL_CXXALIASWARN (fcntl); #elif defined GNULIB_POSIXCHECK # undef fcntl # if HAVE_RAW_DECL_FCNTL @@ -79,10 +84,17 @@ _GL_WARN_ON_USE (fcntl, "fcntl is not always POSIX compliant - " #if @GNULIB_OPEN@ # if @REPLACE_OPEN@ -# undef open -# define open rpl_open -extern int open (const char *filename, int flags, ...) _GL_ARG_NONNULL ((1)); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef open +# define open rpl_open +# endif +_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...)); +# else +_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...)); # endif +_GL_CXXALIASWARN (open); #elif defined GNULIB_POSIXCHECK # undef open /* Assume open is always declared. */ @@ -92,13 +104,25 @@ _GL_WARN_ON_USE (open, "open is not always POSIX compliant - " #if @GNULIB_OPENAT@ # if @REPLACE_OPENAT@ -# undef openat -# define openat rpl_openat -# endif -# if !@HAVE_OPENAT@ || @REPLACE_OPENAT@ -extern int openat (int fd, char const *file, int flags, /* mode_t mode */ ...) - _GL_ARG_NONNULL ((2)); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef openat +# define openat rpl_openat +# endif +_GL_FUNCDECL_RPL (openat, int, + (int fd, char const *file, int flags, /* mode_t mode */ ...) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (openat, int, + (int fd, char const *file, int flags, /* mode_t mode */ ...)); +# else +# if !@HAVE_OPENAT@ +_GL_FUNCDECL_SYS (openat, int, + (int fd, char const *file, int flags, /* mode_t mode */ ...) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (openat, int, + (int fd, char const *file, int flags, /* mode_t mode */ ...)); # endif +_GL_CXXALIASWARN (openat); #elif defined GNULIB_POSIXCHECK # undef openat # if HAVE_RAW_DECL_OPENAT @@ -107,9 +131,6 @@ _GL_WARN_ON_USE (openat, "openat is not portable - " # endif #endif -#ifdef __cplusplus -} -#endif /* Fix up the FD_* macros, only known to be missing on mingw. */ diff --git a/modules/fcntl-h b/modules/fcntl-h index e25c155e2e..3f2305f2c9 100644 --- a/modules/fcntl-h +++ b/modules/fcntl-h @@ -8,6 +8,7 @@ m4/fcntl-o.m4 Depends-on: arg-nonnull +c++defs extensions include_next unistd @@ -21,7 +22,7 @@ BUILT_SOURCES += fcntl.h # We need the following in order to create when the system # doesn't have one that works with the given compiler. -fcntl.h: fcntl.in.h $(WARN_ON_USE_H) $(ARG_NONNULL_H) +fcntl.h: fcntl.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ @@ -35,6 +36,7 @@ fcntl.h: fcntl.in.h $(WARN_ON_USE_H) $(ARG_NONNULL_H) -e 's|@''REPLACE_FCNTL''@|$(REPLACE_FCNTL)|g' \ -e 's|@''REPLACE_OPEN''@|$(REPLACE_OPEN)|g' \ -e 's|@''REPLACE_OPENAT''@|$(REPLACE_OPENAT)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ < $(srcdir)/fcntl.in.h; \ -- 2.30.2