From: Bruno Haible Date: Sat, 3 Apr 2010 16:52:49 +0000 (+0200) Subject: time_r: Fix C++ test error on mingw. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=40b243881abcf500cb03c7274e8ed1fb31468546;p=pspp time_r: Fix C++ test error on mingw. --- diff --git a/ChangeLog b/ChangeLog index 2c21234ff7..2a88359b3c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-04-03 Bruno Haible + + time_r: Fix C++ test error on mingw. + * lib/time.in.h (localtime_r, gmtime_r): Use modern idiom. + * m4/time_r.m4 (gl_TIME_R): When localtime_r does not exist, set + HAVE_LOCALTIME_R to 0, not REPLACE_LOCALTIME_R to 1. + * m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS): Initialize HAVE_LOCALTIME_R. + * modules/time (Makefile.am): Substitute HAVE_LOCALTIME_R. + 2010-04-03 Bruno Haible time_r: Minor updates. diff --git a/lib/time.in.h b/lib/time.in.h index 2fdc7e75f8..35610160cb 100644 --- a/lib/time.in.h +++ b/lib/time.in.h @@ -122,6 +122,11 @@ _GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer, _GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer, struct tm *restrict __result)); # else +# if ! @HAVE_LOCALTIME_R@ +_GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer, + struct tm *restrict __result) + _GL_ARG_NONNULL ((1, 2))); +# endif _GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer, struct tm *restrict __result)); # endif @@ -137,6 +142,11 @@ _GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer, _GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer, struct tm *restrict __result)); # else +# if ! @HAVE_LOCALTIME_R@ +_GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer, + struct tm *restrict __result) + _GL_ARG_NONNULL ((1, 2))); +# endif _GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer, struct tm *restrict __result)); # endif diff --git a/m4/time_h.m4 b/m4/time_h.m4 index f9dfe754eb..ecab80790d 100644 --- a/m4/time_h.m4 +++ b/m4/time_h.m4 @@ -77,6 +77,8 @@ AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS], GNULIB_STRPTIME=0; AC_SUBST([GNULIB_STRPTIME]) GNULIB_TIMEGM=0; AC_SUBST([GNULIB_TIMEGM]) GNULIB_TIME_R=0; AC_SUBST([GNULIB_TIME_R]) + dnl Assume proper GNU behavior unless another module says otherwise. + HAVE_LOCALTIME_R=0; AC_SUBST([HAVE_LOCALTIME_R]) dnl If another module says to replace or to not replace, do that. dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK; dnl this lets maintainers check for portability. diff --git a/m4/time_r.m4 b/m4/time_r.m4 index 8548cb6391..9e82d39ffb 100644 --- a/m4/time_r.m4 +++ b/m4/time_r.m4 @@ -9,29 +9,40 @@ dnl Written by Paul Eggert. AC_DEFUN([gl_TIME_R], [ - dnl Persuade glibc and Solaris to declare localtime_r. + dnl Persuade glibc and Solaris to declare localtime_r. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) AC_REQUIRE([AC_C_RESTRICT]) - AC_CACHE_CHECK([whether localtime_r is compatible with its POSIX signature], - [gl_cv_time_r_posix], - [AC_COMPILE_IFELSE([AC_LANG_PROGRAM( - [[#include ]], - [[/* We don't need to append 'restrict's to the argument types, - even though the POSIX signature has the 'restrict's, - since C99 says they can't affect type compatibility. */ - struct tm * (*ptr) (time_t const *, struct tm *) = localtime_r; - if (ptr) return 0; - /* Check the return type is a pointer. On HP-UX 10 it is 'int'. */ - *localtime_r (0, 0);]])], - [gl_cv_time_r_posix=yes], - [gl_cv_time_r_posix=no])]) - if test $gl_cv_time_r_posix = yes; then - REPLACE_LOCALTIME_R=0 + AC_CHECK_FUNCS_ONCE([localtime_r]) + if test $ac_cv_func_localtime_r = yes; then + AC_CACHE_CHECK([whether localtime_r is compatible with its POSIX signature], + [gl_cv_time_r_posix], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include ]], + [[/* We don't need to append 'restrict's to the argument types, + even though the POSIX signature has the 'restrict's, + since C99 says they can't affect type compatibility. */ + struct tm * (*ptr) (time_t const *, struct tm *) = localtime_r; + if (ptr) return 0; + /* Check the return type is a pointer. + On HP-UX 10 it is 'int'. */ + *localtime_r (0, 0);]]) + ], + [gl_cv_time_r_posix=yes], + [gl_cv_time_r_posix=no]) + ]) + if test $gl_cv_time_r_posix = yes; then + REPLACE_LOCALTIME_R=0 + else + REPLACE_LOCALTIME_R=1 + fi else - REPLACE_LOCALTIME_R=1 + HAVE_LOCALTIME_R=0 + fi + if test $HAVE_LOCALTIME_R = 0 || test $REPLACE_LOCALTIME_R = 1; then AC_LIBOBJ([time_r]) gl_PREREQ_TIME_R fi diff --git a/modules/time b/modules/time index 733c9695b7..bfc208bfa2 100644 --- a/modules/time +++ b/modules/time @@ -32,6 +32,7 @@ time.h: time.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -e 's|@''GNULIB_STRPTIME''@|$(GNULIB_STRPTIME)|g' \ -e 's|@''GNULIB_TIMEGM''@|$(GNULIB_TIMEGM)|g' \ -e 's|@''GNULIB_TIME_R''@|$(GNULIB_TIME_R)|g' \ + -e 's|@''HAVE_LOCALTIME_R''@|$(HAVE_LOCALTIME_R)|g' \ -e 's|@''REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \ -e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \ -e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \