Merge pull request #2750 from cremno/call-c11-timespec_get

mruby-time: call ISO C11's timespec_get() if available
This commit is contained in:
Yukihiro "Matz" Matsumoto
2015-03-23 14:11:19 +09:00
+11 -1
View File
@@ -235,7 +235,17 @@ current_mrb_time(mrb_state *mrb)
struct mrb_time *tm;
tm = (struct mrb_time *)mrb_malloc(mrb, sizeof(*tm));
#ifdef NO_GETTIMEOFDAY
#if defined(TIME_UTC)
{
struct timespec ts;
if (timespec_get(&ts, TIME_UTC) == 0) {
mrb_free(mrb, tm);
mrb_raise(mrb, E_RUNTIME_ERROR, "timespec_get() failed for unknown reasons");
}
tm->sec = ts.tv_sec;
tm->usec = ts.tv_nsec / 1000;
}
#elif defined(NO_GETTIMEOFDAY)
{
static time_t last_sec = 0, last_usec = 0;