* MT safe
*/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include "glib.h"
#include <time.h>
memset (d, 0x0, ndates*sizeof (GDate));
}
-static G_LOCK_DEFINE(g_date_global);
+G_LOCK_DECLARE_STATIC (g_date_global);
/* These are for the parser, output to the user should use *
* g_date_strftime () - this creates more never-freed memory to annoy
/* set invalid */
g_date_clear (d, 1);
- g_lock (g_date_global);
+ G_LOCK (g_date_global);
g_date_prepare_to_parse (str, &pt);
if (pt.num_ints == 4)
{
- g_unlock (g_date_global);
+ G_UNLOCK (g_date_global);
return; /* presumably a typo; bail out. */
}
else
g_message ("Rejected DMY %u %u %u", day, m, y);
#endif
- g_unlock (g_date_global);
+ G_UNLOCK (g_date_global);
}
void
GTime time)
{
time_t t = time;
- struct tm *tm;
+ struct tm tm;
g_return_if_fail (d != NULL);
- tm = localtime (&t);
+#ifdef HAVE_LOCALTIME_R
+ localtime_r (&t, &tm);
+#else
+# ifdef G_THREADS_ENABLED
+# warning "the `g_date_set_time' function will not be MT-safe"
+# warning "because there is no `localtime_r' on your system."
+# endif
+ {
+ struct tm *ptm = localtime (&t);
+ g_assert (ptm);
+ memcpy ((void *) &tm, (void *) ptm, sizeof(struct tm));
+ }
+#endif
- if (tm)
- {
- d->julian = FALSE;
-
- d->month = tm->tm_mon + 1;
- d->day = tm->tm_mday;
- d->year = tm->tm_year + 1900;
-
- g_return_if_fail (g_date_valid_dmy (d->day, d->month, d->year));
-
- d->dmy = TRUE;
- }
- else
- {
- g_date_clear (d, 1);
- }
+ d->julian = FALSE;
+
+ d->month = tm.tm_mon + 1;
+ d->day = tm.tm_mday;
+ d->year = tm.tm_year + 1900;
+
+ g_return_if_fail (g_date_valid_dmy (d->day, d->month, d->year));
+
+ d->dmy = TRUE;
}
void