[glib] Fix Win32 build
- From: Tor Lillqvist <tml src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Fix Win32 build
- Date: Thu, 26 Aug 2010 09:42:19 +0000 (UTC)
commit 3c86a77ae5efa57a6f62c2eeec9c67aa66246496
Author: Tor Lillqvist <tml iki fi>
Date: Thu Aug 26 12:41:46 2010 +0300
Fix Win32 build
configure.ac | 1 +
glib/gdatetime.c | 2 +-
glib/tests/gdatetime.c | 26 +++++++++++++++++++++++---
3 files changed, 25 insertions(+), 4 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 2c0c958..dab2049 100644
--- a/configure.ac
+++ b/configure.ac
@@ -882,6 +882,7 @@ AC_CHECK_MEMBERS([struct stat.st_blksize, struct stat.st_blocks, struct statfs.f
#endif])
# struct statvfs.f_basetype is available on Solaris but not for Linux.
AC_CHECK_MEMBERS([struct statvfs.f_basetype],,, [#include <sys/statvfs.h>])
+AC_CHECK_MEMBERS([struct tm.tm_gmtoff])
# Checks for libcharset
AM_LANGINFO_CODESET
diff --git a/glib/gdatetime.c b/glib/gdatetime.c
index baf0c5f..d03ac0c 100644
--- a/glib/gdatetime.c
+++ b/glib/gdatetime.c
@@ -1700,7 +1700,7 @@ g_date_time_new_from_epoch (gint64 t) /* IN */
localtime_r (&tt, &tm);
#else
{
- struct tm *ptm = localtime (&timet);
+ struct tm *ptm = localtime (&tt);
if (ptm == NULL)
{
diff --git a/glib/tests/gdatetime.c b/glib/tests/gdatetime.c
index b651b5b..f0a0e55 100644
--- a/glib/tests/gdatetime.c
+++ b/glib/tests/gdatetime.c
@@ -54,9 +54,9 @@ get_localtime_tm (time_t time_,
g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, "ptm != NULL");
#endif
- tm.tm_mon = 0;
- tm.tm_mday = 1;
- tm.tm_year = 100;
+ retval->tm_mon = 0;
+ retval->tm_mday = 1;
+ retval->tm_year = 100;
}
else
memcpy ((void *) retval, (void *) ptm, sizeof (struct tm));
@@ -718,7 +718,18 @@ test_GDateTime_utc_now (void)
struct tm tm;
t = time (NULL);
+#ifdef HAVE_GMTIME_R
gmtime_r (&t, &tm);
+#else
+ {
+ struct tm *tmp = gmtime (&t);
+ /* Assume gmtime() can't fail as we got t from time(NULL). (Note
+ * that on Windows, gmtime() *is* MT-safe, it uses a thread-local
+ * buffer.)
+ */
+ memcpy (&tm, tmp, sizeof (struct tm));
+ }
+#endif
dt = g_date_time_new_utc_now ();
g_assert_cmpint (tm.tm_year + 1900, ==, g_date_time_get_year (dt));
g_assert_cmpint (tm.tm_mon + 1, ==, g_date_time_get_month (dt));
@@ -741,7 +752,9 @@ test_GDateTime_get_utc_offset (void)
dt = g_date_time_new_now ();
ts = g_date_time_get_utc_offset (dt);
+#ifdef HAVE_STRUCT_TM_TM_GMTOFF
g_assert_cmpint (ts, ==, (tm.tm_gmtoff * G_TIME_SPAN_SECOND));
+#endif
g_date_time_unref (dt);
}
@@ -791,7 +804,14 @@ test_GDateTime_to_utc (void)
struct tm tm;
t = time (NULL);
+#ifdef HAVE_GMTIME_R
gmtime_r (&t, &tm);
+#else
+ {
+ struct tm *tmp = gmtime (&t);
+ memcpy (&tm, tmp, sizeof (struct tm));
+ }
+#endif
dt2 = g_date_time_new_now ();
dt = g_date_time_to_utc (dt2);
g_assert_cmpint (tm.tm_year + 1900, ==, g_date_time_get_year (dt));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]