From 6618b0355c9923a0049b84540cd45bd9556cac89 Mon Sep 17 00:00:00 2001 From: Phil Krylov Date: Tue, 24 May 2005 11:52:46 +0000 Subject: [PATCH] Added detection of platforms which don't have external timezone and daylight variables, and emulation of these variables. --- configure | 123 ++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 16 ++++++ dlls/msvcrt/time.c | 18 +++++++ include/config.h.in | 6 +++ 4 files changed, 163 insertions(+) diff --git a/configure b/configure index 3c254faae5b..42e19d30c53 100755 --- a/configure +++ b/configure @@ -19760,6 +19760,129 @@ _ACEOF fi +echo "$as_me:$LINENO: checking for timezone variable" >&5 +echo $ECHO_N "checking for timezone variable... $ECHO_C" >&6 +if test "${ac_cv_have_timezone+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +int +main () +{ +timezone; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_have_timezone="yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_have_timezone="no" +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_have_timezone" >&5 +echo "${ECHO_T}$ac_cv_have_timezone" >&6 +if test "$ac_cv_have_timezone" = "yes" +then + +cat >>confdefs.h <<\_ACEOF +#define HAVE_TIMEZONE 1 +_ACEOF + +fi +echo "$as_me:$LINENO: checking for daylight variable" >&5 +echo $ECHO_N "checking for daylight variable... $ECHO_C" >&6 +if test "${ac_cv_have_daylight+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +int +main () +{ +daylight; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_have_daylight="yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_have_daylight="no" +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_have_daylight" >&5 +echo "${ECHO_T}$ac_cv_have_daylight" >&6 +if test "$ac_cv_have_daylight" = "yes" +then + +cat >>confdefs.h <<\_ACEOF +#define HAVE_DAYLIGHT 1 +_ACEOF + +fi + case $host_cpu in *i[3456789]86*) echo "$as_me:$LINENO: checking whether we need to define __i386__" >&5 diff --git a/configure.ac b/configure.ac index d09fdab4fb3..3fd80dfdc38 100644 --- a/configure.ac +++ b/configure.ac @@ -1474,6 +1474,22 @@ AC_CHECK_MEMBERS([struct option.name],,, dnl Check for stat.st_blocks AC_CHECK_MEMBERS([struct stat.st_blocks]) +dnl Check for the external timezone variables timezone and daylight +AC_CACHE_CHECK([for timezone variable], ac_cv_have_timezone, + AC_TRY_LINK([#include ],[timezone;], + ac_cv_have_timezone="yes", ac_cv_have_timezone="no")) +if test "$ac_cv_have_timezone" = "yes" +then + AC_DEFINE(HAVE_TIMEZONE, 1, [Define if you have the timezone variable]) +fi +AC_CACHE_CHECK([for daylight variable], ac_cv_have_daylight, + AC_TRY_LINK([#include ],[daylight;], + ac_cv_have_daylight="yes", ac_cv_have_daylight="no")) +if test "$ac_cv_have_daylight" = "yes" +then + AC_DEFINE(HAVE_DAYLIGHT, 1, [Define if you have the daylight variable]) +fi + dnl *** check for the need to define platform-specific symbols case $host_cpu in diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c index 9178412799b..e2a0359894a 100644 --- a/dlls/msvcrt/time.c +++ b/dlls/msvcrt/time.c @@ -348,8 +348,26 @@ char **__p__tzname(void) void MSVCRT__tzset(void) { tzset(); +#if defined(HAVE_TIMEZONE) && defined(HAVE_DAYLIGHT) MSVCRT___daylight = daylight; MSVCRT___timezone = timezone; +#else + { + static const time_t seconds_in_year = (365 * 24 + 6) * 3600; + time_t t; + struct tm *tmp; + long zone_january, zone_july; + + t = (time((time_t *)0) / seconds_in_year) * seconds_in_year; + tmp = localtime(&t); + zone_january = -tmp->tm_gmtoff; + t += seconds_in_year / 2; + tmp = localtime(&t); + zone_july = -tmp->tm_gmtoff; + MSVCRT___daylight = (zone_january != zone_july); + MSVCRT___timezone = max(zone_january, zone_july); + } +#endif lstrcpynA(tzname_std, tzname[0], sizeof(tzname_std)); tzname_std[sizeof(tzname_std) - 1] = '\0'; lstrcpynA(tzname_dst, tzname[1], sizeof(tzname_dst)); diff --git a/include/config.h.in b/include/config.h.in index 2f709e23ecd..05590d44f0d 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -71,6 +71,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_CURSES_H +/* Define if you have the daylight variable */ +#undef HAVE_DAYLIGHT + /* Define to 1 if you have the header file. */ #undef HAVE_DIRECT_H @@ -740,6 +743,9 @@ /* Define to 1 if you have the `timegm' function. */ #undef HAVE_TIMEGM +/* Define if you have the timezone variable */ +#undef HAVE_TIMEZONE + /* Define to 1 if you have the header file. */ #undef HAVE_UCONTEXT_H