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 <errno.h> | 8 #include <errno.h> |
8 #include <math.h> | 9 #include <math.h> |
9 #include <sys/stat.h> | 10 #include <sys/stat.h> |
11 #include <sys/syscall.h> | |
10 #include <time64.h> | 12 #include <time64.h> |
11 | 13 |
12 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
13 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
14 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
15 | 17 |
18 extern "C" { | |
16 // There is no futimes() avaiable in Bionic, so we provide our own | 19 // There is no futimes() avaiable in Bionic, so we provide our own |
17 // implementation until it is there. | 20 // implementation until it is there. |
18 extern "C" { | |
19 | |
20 int futimes(int fd, const struct timeval tv[2]) { | 21 int futimes(int fd, const struct timeval tv[2]) { |
21 const std::string fd_path = base::StringPrintf("/proc/self/fd/%d", fd); | 22 // Convert timeval to timespec. |
22 return utimes(fd_path.c_str(), tv); | 23 // timeval.usec is guaranteed to be less than one million. |
Mark Mentovai
2013/06/06 13:37:44
Guaranteed by whom? Any old user code might call t
nilesh
2013/06/06 19:03:14
Thanks. Done.
| |
24 struct timespec ts[2]; | |
25 ts[0].tv_sec = tv[0].tv_sec; | |
Mark Mentovai
2013/06/06 13:37:44
tv is allowed to be NULL, in which case you would
nilesh
2013/06/06 19:03:14
Done.
| |
26 ts[0].tv_nsec = tv[0].tv_usec * 1000; | |
Mark Mentovai
2013/06/06 13:37:44
Normally you could use TIMEVAL_TO_TIMESPEC(&tv, &t
nilesh
2013/06/06 19:03:14
You are right. TIMEVAL_TO_TIMESPEC is not avialabl
| |
27 ts[1].tv_sec = tv[1].tv_sec; | |
28 ts[1].tv_nsec = tv[1].tv_usec * 1000; | |
29 return syscall(__NR_utimensat, fd, NULL, ts, 0); | |
23 } | 30 } |
24 | 31 |
25 // Android has only timegm64() and no timegm(). | 32 // Android has only timegm64() and no timegm(). |
26 // We replicate the behaviour of timegm() when the result overflows time_t. | 33 // We replicate the behaviour of timegm() when the result overflows time_t. |
27 time_t timegm(struct tm* const t) { | 34 time_t timegm(struct tm* const t) { |
28 // time_t is signed on Android. | 35 // time_t is signed on Android. |
29 static const time_t kTimeMax = ~(1 << (sizeof(time_t) * CHAR_BIT - 1)); | 36 static const time_t kTimeMax = ~(1 << (sizeof(time_t) * CHAR_BIT - 1)); |
30 static const time_t kTimeMin = (1 << (sizeof(time_t) * CHAR_BIT - 1)); | 37 static const time_t kTimeMin = (1 << (sizeof(time_t) * CHAR_BIT - 1)); |
31 time64_t result = timegm64(t); | 38 time64_t result = timegm64(t); |
32 if (result < kTimeMin || result > kTimeMax) | 39 if (result < kTimeMin || result > kTimeMax) |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 // The directory doesn't exist, but an error occured | 153 // The directory doesn't exist, but an error occured |
147 return NULL; | 154 return NULL; |
148 } | 155 } |
149 } | 156 } |
150 | 157 |
151 // We reached the max number of tries. | 158 // We reached the max number of tries. |
152 return NULL; | 159 return NULL; |
153 } | 160 } |
154 | 161 |
155 } // extern "C" | 162 } // extern "C" |
OLD | NEW |