summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authornileshagrawal@chromium.org <nileshagrawal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-16 03:18:13 +0000
committernileshagrawal@chromium.org <nileshagrawal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-16 03:18:13 +0000
commitc5395182c545132ad8fbb91faba4bda897034c45 (patch)
treea7a16b9997d85ba23dfe8f8d5e392cc9f041e56e /base
parentd79d222d1668b89224c2d0a56499827c9c9d0a94 (diff)
downloadchromium_src-c5395182c545132ad8fbb91faba4bda897034c45.zip
chromium_src-c5395182c545132ad8fbb91faba4bda897034c45.tar.gz
chromium_src-c5395182c545132ad8fbb91faba4bda897034c45.tar.bz2
Fix timegm behavior for android.
time_t on android is 32 bit. We should detect overflow and return -1. BUG= TEST= Review URL: http://codereview.chromium.org/8976004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114762 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/os_compat_android.cc14
-rw-r--r--base/os_compat_android.h11
2 files changed, 18 insertions, 7 deletions
diff --git a/base/os_compat_android.cc b/base/os_compat_android.cc
index d500656..e8b6e2f 100644
--- a/base/os_compat_android.cc
+++ b/base/os_compat_android.cc
@@ -4,6 +4,8 @@
#include "base/os_compat_android.h"
+#include <time64.h>
+
#include "base/stringprintf.h"
// There is no futimes() avaiable in Bionic, so we provide our own
@@ -15,4 +17,16 @@ int futimes(int fd, const struct timeval tv[2]) {
return utimes(fd_path.c_str(), tv);
}
+// Android has only timegm64() and no timegm().
+// We replicate the behaviour of timegm() when the result overflows time_t.
+time_t timegm(struct tm* const t) {
+ // time_t is signed on Android.
+ static const time_t kTimeMax = ~(1 << (sizeof(time_t) * CHAR_BIT - 1));
+ static const time_t kTimeMin = (1 << (sizeof(time_t) * CHAR_BIT - 1));
+ time64_t result = timegm64(t);
+ if (result < kTimeMin || result > kTimeMax)
+ return -1;
+ return result;
+}
+
} // extern "C"
diff --git a/base/os_compat_android.h b/base/os_compat_android.h
index af6e167..e43319d 100644
--- a/base/os_compat_android.h
+++ b/base/os_compat_android.h
@@ -8,15 +8,17 @@
#include <fcntl.h>
#include <sys/types.h>
-#include <time64.h>
#include <utime.h>
-// Not implemented in Bionic. See platform_file_android.cc.
+// Not implemented in Bionic.
extern "C" int futimes(int fd, const struct timeval tv[2]);
// The prototype of mkdtemp is missing.
extern "C" char* mkdtemp(char* path);
+// Android has no timegm().
+extern "C" time_t timegm(struct tm* const t);
+
// The lockf() function is not available on Android; we translate to flock().
#define F_LOCK LOCK_EX
#define F_ULOCK LOCK_UN
@@ -24,9 +26,4 @@ inline int lockf(int fd, int cmd, off_t ignored_len) {
return flock(fd, cmd);
}
-// Android has only timegm64() and no timegm().
-inline time_t timegm(struct tm* const tmp) {
- return static_cast<time_t>(timegm64(tmp));
-}
-
#endif // BASE_OS_COMPAT_ANDROID_H_