Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2010)

Unified Diff: base/time_posix.cc

Issue 5434001: Help make Base compile under NaCl... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(&timestruct);
else
+#if defined(OS_NACL)
+ seconds = my_timegm(&timestruct);
+#else
seconds = timegm(&timestruct);
+#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
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698