| 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> |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 ts[0].tv_nsec = tv[0].tv_usec * 1000; | 34 ts[0].tv_nsec = tv[0].tv_usec * 1000; |
| 35 ts[1].tv_sec = tv[1].tv_sec; | 35 ts[1].tv_sec = tv[1].tv_sec; |
| 36 ts[1].tv_nsec = tv[1].tv_usec * 1000; | 36 ts[1].tv_nsec = tv[1].tv_usec * 1000; |
| 37 return syscall(__NR_utimensat, fd, NULL, ts, 0); | 37 return syscall(__NR_utimensat, fd, NULL, ts, 0); |
| 38 } | 38 } |
| 39 | 39 |
| 40 // Android has only timegm64() and no timegm(). | 40 // Android has only timegm64() and no timegm(). |
| 41 // We replicate the behaviour of timegm() when the result overflows time_t. | 41 // We replicate the behaviour of timegm() when the result overflows time_t. |
| 42 time_t timegm(struct tm* const t) { | 42 time_t timegm(struct tm* const t) { |
| 43 // time_t is signed on Android. | 43 // time_t is signed on Android. |
| 44 static const time_t kTimeMax = ~(1 << (sizeof(time_t) * CHAR_BIT - 1)); | 44 static const time_t kTimeMax = ~(1L << (sizeof(time_t) * CHAR_BIT - 1)); |
| 45 static const time_t kTimeMin = (1 << (sizeof(time_t) * CHAR_BIT - 1)); | 45 static const time_t kTimeMin = (1L << (sizeof(time_t) * CHAR_BIT - 1)); |
| 46 time64_t result = timegm64(t); | 46 time64_t result = timegm64(t); |
| 47 if (result < kTimeMin || result > kTimeMax) | 47 if (result < kTimeMin || result > kTimeMax) |
| 48 return -1; | 48 return -1; |
| 49 return result; | 49 return result; |
| 50 } | 50 } |
| 51 | 51 |
| 52 // The following is only needed when building with GCC 4.6 or higher | 52 // 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). | 53 // (i.e. not with Android GCC 4.4.3, nor with Clang). |
| 54 // | 54 // |
| 55 // GCC is now capable of optimizing successive calls to sin() and cos() into | 55 // GCC is now capable of optimizing successive calls to sin() and cos() into |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 // The directory doesn't exist, but an error occured | 162 // The directory doesn't exist, but an error occured |
| 163 return NULL; | 163 return NULL; |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 | 166 |
| 167 // We reached the max number of tries. | 167 // We reached the max number of tries. |
| 168 return NULL; | 168 return NULL; |
| 169 } | 169 } |
| 170 | 170 |
| 171 } // extern "C" | 171 } // extern "C" |
| OLD | NEW |