sys_time: Avoid #define replacements in C++ mode.
authorBruno Haible <bruno@clisp.org>
Mon, 8 Mar 2010 00:41:33 +0000 (01:41 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 8 Mar 2010 02:11:14 +0000 (03:11 +0100)
ChangeLog
lib/sys_time.in.h
modules/sys_time

index 439a10c..e99715c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2010-03-07  Bruno Haible  <bruno@clisp.org>
 
+       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,
index fe7f624..6e0c7db 100644 (file)
 #  include <time.h>
 # 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 */
index adfa493..4df85d7 100644 (file)
@@ -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 <sys/time.h> 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; \