From 97d3a111c8a830335af6150a4a0f8712b281902f Mon Sep 17 00:00:00 2001 From: Brian Ford Date: Wed, 19 Jan 2011 18:43:16 -0800 Subject: [PATCH] Added localtime_r and gmtime_r for Windows. --- vm/builtin/time.cpp | 6 ++++++ vm/missing/windows.c | 3 ++- vm/windows_compat.h | 22 ++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/vm/builtin/time.cpp b/vm/builtin/time.cpp index 5204ea1ee8..c9bec75392 100644 --- a/vm/builtin/time.cpp +++ b/vm/builtin/time.cpp @@ -1,3 +1,5 @@ +#include "config.h" + #include "vm.hpp" #include "vm/object_utils.hpp" #include "objectmemory.hpp" @@ -15,6 +17,8 @@ #include #include +#include "windows_compat.h" + namespace rubinius { void Time::init(STATE) { GO(time_class).set(state->new_class("Time", G(object))); @@ -103,8 +107,10 @@ namespace rubinius { } tm.tm_wday = -1; +#ifndef RBX_WINDOWS tm.tm_gmtoff = 0; tm.tm_zone = 0; +#endif tm.tm_year = year->to_native() - 1900; tm.tm_isdst = isdst->to_native(); diff --git a/vm/missing/windows.c b/vm/missing/windows.c index 0486fd0497..40bf2e3202 100644 --- a/vm/missing/windows.c +++ b/vm/missing/windows.c @@ -1,11 +1,12 @@ #ifdef RBX_WINDOWS -#include "windows_compat.h" #include #include #include #include +#include "windows_compat.h" + int uname(struct utsname *name) { rubinius::abort(); return -1 diff --git a/vm/windows_compat.h b/vm/windows_compat.h index fe53e3c56b..cd5bc106ce 100644 --- a/vm/windows_compat.h +++ b/vm/windows_compat.h @@ -172,6 +172,28 @@ char* realpath(const char* file_name, char* resolved_name); time_t timegm(struct tm* tm); int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); +#ifndef localtime_r +#define localtime_r(_Time, _Tm) ({ \ + struct tm *___tmp_tm = localtime((_Time)); \ + if (___tmp_tm) { \ + *(_Tm) = *___tmp_tm; \ + ___tmp_tm = (_Tm); \ + } \ + ___tmp_tm; \ +}) +#endif + +#ifndef gmtime_r +#define gmtime_r(_Time,_Tm) ({ \ + struct tm *___tmp_tm = gmtime((_Time)); \ + if (___tmp_tm) { \ + *(_Tm) = *___tmp_tm; \ + ___tmp_tm = (_Tm); \ + } \ + ___tmp_tm; \ +}) +#endif + #define RBX_USEC_PER_SEC 1000000 #define timeradd(tvp, uvp, vvp) \ do { \