| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/os_compat_android.h" | 5 #include "base/os_compat_android.h" |
| 6 | 6 |
| 7 #include <asm/unistd.h> | 7 #include <asm/unistd.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <math.h> | 9 #include <math.h> |
| 10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
| 11 #include <sys/syscall.h> | 11 #include <sys/syscall.h> |
| 12 |
| 13 #if !defined(__LP64__) |
| 12 #include <time64.h> | 14 #include <time64.h> |
| 15 #endif |
| 13 | 16 |
| 14 #include "base/rand_util.h" | 17 #include "base/rand_util.h" |
| 15 #include "base/strings/string_piece.h" | 18 #include "base/strings/string_piece.h" |
| 16 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 17 | 20 |
| 18 extern "C" { | 21 extern "C" { |
| 19 // There is no futimes() avaiable in Bionic, so we provide our own | 22 // There is no futimes() avaiable in Bionic, so we provide our own |
| 20 // implementation until it is there. | 23 // implementation until it is there. |
| 21 int futimes(int fd, const struct timeval tv[2]) { | 24 int futimes(int fd, const struct timeval tv[2]) { |
| 22 if (tv == NULL) | 25 if (tv == NULL) |
| 23 return syscall(__NR_utimensat, fd, NULL, NULL, 0); | 26 return syscall(__NR_utimensat, fd, NULL, NULL, 0); |
| 24 | 27 |
| 25 if (tv[0].tv_usec < 0 || tv[0].tv_usec >= 1000000 || | 28 if (tv[0].tv_usec < 0 || tv[0].tv_usec >= 1000000 || |
| 26 tv[1].tv_usec < 0 || tv[1].tv_usec >= 1000000) { | 29 tv[1].tv_usec < 0 || tv[1].tv_usec >= 1000000) { |
| 27 errno = EINVAL; | 30 errno = EINVAL; |
| 28 return -1; | 31 return -1; |
| 29 } | 32 } |
| 30 | 33 |
| 31 // Convert timeval to timespec. | 34 // Convert timeval to timespec. |
| 32 struct timespec ts[2]; | 35 struct timespec ts[2]; |
| 33 ts[0].tv_sec = tv[0].tv_sec; | 36 ts[0].tv_sec = tv[0].tv_sec; |
| 34 ts[0].tv_nsec = tv[0].tv_usec * 1000; | 37 ts[0].tv_nsec = tv[0].tv_usec * 1000; |
| 35 ts[1].tv_sec = tv[1].tv_sec; | 38 ts[1].tv_sec = tv[1].tv_sec; |
| 36 ts[1].tv_nsec = tv[1].tv_usec * 1000; | 39 ts[1].tv_nsec = tv[1].tv_usec * 1000; |
| 37 return syscall(__NR_utimensat, fd, NULL, ts, 0); | 40 return syscall(__NR_utimensat, fd, NULL, ts, 0); |
| 38 } | 41 } |
| 39 | 42 |
| 40 // Android has only timegm64() and no timegm(). | 43 #if !defined(__LP64__) |
| 44 // 32-bit Android has only timegm64() and not timegm(). |
| 41 // We replicate the behaviour of timegm() when the result overflows time_t. | 45 // We replicate the behaviour of timegm() when the result overflows time_t. |
| 42 time_t timegm(struct tm* const t) { | 46 time_t timegm(struct tm* const t) { |
| 43 // time_t is signed on Android. | 47 // time_t is signed on Android. |
| 44 static const time_t kTimeMax = ~(1L << (sizeof(time_t) * CHAR_BIT - 1)); | 48 static const time_t kTimeMax = ~(1L << (sizeof(time_t) * CHAR_BIT - 1)); |
| 45 static const time_t kTimeMin = (1L << (sizeof(time_t) * CHAR_BIT - 1)); | 49 static const time_t kTimeMin = (1L << (sizeof(time_t) * CHAR_BIT - 1)); |
| 46 time64_t result = timegm64(t); | 50 time64_t result = timegm64(t); |
| 47 if (result < kTimeMin || result > kTimeMax) | 51 if (result < kTimeMin || result > kTimeMax) |
| 48 return -1; | 52 return -1; |
| 49 return result; | 53 return result; |
| 50 } | 54 } |
| 55 #endif |
| 51 | 56 |
| 52 // The following is only needed when building with GCC 4.6 or higher | 57 // The following is only needed when building with GCC 4.6 or higher |
| 53 // (i.e. not with Android GCC 4.4.3, nor with Clang). | 58 // (i.e. not with Android GCC 4.4.3, nor with Clang). |
| 54 // | 59 // |
| 55 // GCC is now capable of optimizing successive calls to sin() and cos() into | 60 // GCC is now capable of optimizing successive calls to sin() and cos() into |
| 56 // a single call to sincos(). This means that source code that looks like: | 61 // a single call to sincos(). This means that source code that looks like: |
| 57 // | 62 // |
| 58 // double c, s; | 63 // double c, s; |
| 59 // c = cos(angle); | 64 // c = cos(angle); |
| 60 // s = sin(angle); | 65 // s = sin(angle); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 // The directory doesn't exist, but an error occured | 167 // The directory doesn't exist, but an error occured |
| 163 return NULL; | 168 return NULL; |
| 164 } | 169 } |
| 165 } | 170 } |
| 166 | 171 |
| 167 // We reached the max number of tries. | 172 // We reached the max number of tries. |
| 168 return NULL; | 173 return NULL; |
| 169 } | 174 } |
| 170 | 175 |
| 171 } // extern "C" | 176 } // extern "C" |
| OLD | NEW |