diff options
author | nileshagrawal@chromium.org <nileshagrawal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-16 03:18:13 +0000 |
---|---|---|
committer | nileshagrawal@chromium.org <nileshagrawal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-16 03:18:13 +0000 |
commit | c5395182c545132ad8fbb91faba4bda897034c45 (patch) | |
tree | a7a16b9997d85ba23dfe8f8d5e392cc9f041e56e /base/os_compat_android.cc | |
parent | d79d222d1668b89224c2d0a56499827c9c9d0a94 (diff) | |
download | chromium_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/os_compat_android.cc')
-rw-r--r-- | base/os_compat_android.cc | 14 |
1 files changed, 14 insertions, 0 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" |