Skip to content

Commit

Permalink
Fix Win32 build
Browse files Browse the repository at this point in the history
  • Loading branch information
tml1024 committed Aug 26, 2010
1 parent ca26f9a commit 3c86a77
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion glib/gdatetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
26 changes: 23 additions & 3 deletions glib/tests/gdatetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand All @@ -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);
}

Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 3c86a77

Please sign in to comment.