summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2015-03-23 14:11:19 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2015-03-23 14:11:19 +0900
commit0573306f510b9503f6baa7e9e1d158205add503d (patch)
tree7e68e766c8a54e7b7db3e99d00b1827c81de40b3
parent2249afce256d9e811db4c4b6f3b3982aac5623ca (diff)
parentc47cc0c3bbeece6f08870255b9b21db326678ba3 (diff)
downloadmruby-0573306f510b9503f6baa7e9e1d158205add503d.tar.gz
mruby-0573306f510b9503f6baa7e9e1d158205add503d.zip
Merge pull request #2750 from cremno/call-c11-timespec_get
mruby-time: call ISO C11's timespec_get() if available
-rw-r--r--mrbgems/mruby-time/src/time.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c
index 36cf0a732..b377f3e33 100644
--- a/mrbgems/mruby-time/src/time.c
+++ b/mrbgems/mruby-time/src/time.c
@@ -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;