From: Bruno Haible Date: Mon, 8 Mar 2010 00:41:33 +0000 (+0100) Subject: sys_time: Avoid #define replacements in C++ mode. X-Git-Tag: v0.1~4540 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=e650136cc4a199e64a3b3401cf7e2195b0f3a3ac;p=gnulib.git sys_time: Avoid #define replacements in C++ mode. --- diff --git a/ChangeLog b/ChangeLog index 439a10cef..e99715c8f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2010-03-07 Bruno Haible + sys_time: Avoid #define replacements in C++ mode. + * lib/sys_time.in.h: Include c++defs.h. + (gettimeofday): In C++, define a namespaced alias symbol. + * modules/sys_time (Depends-on): Add c++defs. + (Makefile.am): Update sys/time.h rule. + sys_stat: Avoid #define replacements in C++ mode. * lib/sys_stat.in.h: Include c++defs.h. (fchmodat, fstat, fstatat, futimens, lchmod, lstat, mkdir, mkdirat, diff --git a/lib/sys_time.in.h b/lib/sys_time.in.h index fe7f62435..6e0c7db98 100644 --- a/lib/sys_time.in.h +++ b/lib/sys_time.in.h @@ -39,13 +39,15 @@ # include # 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. */ -#ifdef __cplusplus +# ifdef __cplusplus extern "C" { -#endif +# endif # if ! @HAVE_STRUCT_TIMEVAL@ struct timeval @@ -55,15 +57,33 @@ struct timeval }; # endif +# ifdef __cplusplus +} +# endif + # if @GNULIB_GETTIMEOFDAY@ # if @REPLACE_GETTIMEOFDAY@ -# undef gettimeofday -# define gettimeofday rpl_gettimeofday -# endif -# if @REPLACE_GETTIMEOFDAY@ || !@HAVE_GETTIMEOFDAY@ -extern int gettimeofday (struct timeval *restrict, void *restrict) - _GL_ARG_NONNULL ((1)); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef gettimeofday +# define gettimeofday rpl_gettimeofday +# endif +_GL_FUNCDECL_RPL (gettimeofday, int, + (struct timeval *restrict, void *restrict) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (gettimeofday, int, + (struct timeval *restrict, void *restrict)); +# else +# if !@HAVE_GETTIMEOFDAY@ +_GL_FUNCDECL_SYS (gettimeofday, int, + (struct timeval *restrict, void *restrict) + _GL_ARG_NONNULL ((1))); +# endif +/* Need to cast, because on glibc systems, by default, the second argument is + struct timezone *. */ +_GL_CXXALIAS_SYS_CAST (gettimeofday, int, + (struct timeval *restrict, void *restrict)); # endif +_GL_CXXALIASWARN (gettimeofday); # elif defined GNULIB_POSIXCHECK # undef gettimeofday # if HAVE_RAW_DECL_GETTIMEOFDAY @@ -72,8 +92,4 @@ _GL_WARN_ON_USE (gettimeofday, "gettimeofday is unportable - " # endif # endif -#ifdef __cplusplus -} -#endif - #endif /* _GL_SYS_TIME_H */ diff --git a/modules/sys_time b/modules/sys_time index adfa49386..4df85d7e4 100644 --- a/modules/sys_time +++ b/modules/sys_time @@ -8,6 +8,7 @@ m4/sys_time_h.m4 Depends-on: include_next arg-nonnull +c++defs warn-on-use configure.ac: @@ -19,7 +20,7 @@ BUILT_SOURCES += sys/time.h # We need the following in order to create when the system # doesn't have one that works with the given compiler. -sys/time.h: sys_time.in.h $(WARN_ON_USE_H) $(ARG_NONNULL_H) +sys/time.h: sys_time.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) $(AM_V_at)$(MKDIR_P) sys $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ @@ -31,6 +32,7 @@ sys/time.h: sys_time.in.h $(WARN_ON_USE_H) $(ARG_NONNULL_H) -e 's/@''HAVE_GETTIMEOFDAY''@/$(HAVE_GETTIMEOFDAY)/g' \ -e 's/@''HAVE_STRUCT_TIMEVAL''@/$(HAVE_STRUCT_TIMEVAL)/g' \ -e 's/@''REPLACE_GETTIMEOFDAY''@/$(REPLACE_GETTIMEOFDAY)/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)/sys_time.in.h; \