Index: base/time_posix.cc |
=================================================================== |
--- base/time_posix.cc (revision 67731) |
+++ base/time_posix.cc (working copy) |
@@ -60,6 +60,26 @@ |
return Now(); |
} |
+#if defined(OS_NACL) |
+#include <stdlib.h> |
+// NaCl doesn't have timegm, so we use this hack for now. |
+// http://code.google.com/p/nativeclient/issues/detail?id=1160 |
brettw
2010/12/01 22:59:56
I'd like to at least see a comment here about why
|
+static time_t my_timegm (struct tm *tm) { |
+ time_t ret; |
+ char *tz; |
+ tz = getenv("TZ"); |
+ setenv("TZ", "", 1); |
+ tzset(); |
+ ret = mktime(tm); |
+ if (tz) |
+ setenv("TZ", tz, 1); |
+ else |
+ unsetenv("TZ"); |
+ tzset(); |
+ return ret; |
+} |
+#endif |
+ |
// static |
Time Time::FromExploded(bool is_local, const Exploded& exploded) { |
struct tm timestruct; |
@@ -72,14 +92,20 @@ |
timestruct.tm_wday = exploded.day_of_week; // mktime/timegm ignore this |
timestruct.tm_yday = 0; // mktime/timegm ignore this |
timestruct.tm_isdst = -1; // attempt to figure it out |
+#if !defined(OS_NACL) |
timestruct.tm_gmtoff = 0; // not a POSIX field, so mktime/timegm ignore |
timestruct.tm_zone = NULL; // not a POSIX field, so mktime/timegm ignore |
+#endif |
time_t seconds; |
if (is_local) |
seconds = mktime(×truct); |
else |
+#if defined(OS_NACL) |
+ seconds = my_timegm(×truct); |
+#else |
seconds = timegm(×truct); |
+#endif |
int64 milliseconds; |
// Handle overflow. Clamping the range to what mktime and timegm might |
@@ -166,6 +192,14 @@ |
return TimeTicks(absolute_micro); |
} |
+#elif defined(OS_NACL) |
+TimeTicks TimeTicks::Now() { |
+ // NaCl sadly does not have _POSIX_TIMERS enabled in sys/features.h |
+ // Apparently NaCl only has CLOCK_REALTIME: |
+ // http://code.google.com/p/nativeclient/issues/detail?id=1159 |
+ return TimeTicks(clock()); |
+} |
+ |
#else // _POSIX_MONOTONIC_CLOCK |
#error No usable tick clock function on this platform. |
#endif // _POSIX_MONOTONIC_CLOCK |