OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
7 | 7 |
8 #include "bin/file.h" | 8 #include "bin/file.h" |
9 | 9 |
10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 | 286 |
287 int64_t File::LengthFromPath(const char* name) { | 287 int64_t File::LengthFromPath(const char* name) { |
288 struct stat st; | 288 struct stat st; |
289 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { | 289 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { |
290 return st.st_size; | 290 return st.st_size; |
291 } | 291 } |
292 return -1; | 292 return -1; |
293 } | 293 } |
294 | 294 |
295 | 295 |
| 296 static int64_t TimespecToMilliseconds(const struct timespec& t) { |
| 297 return static_cast<int64_t>(t.tv_sec) * 1000L + |
| 298 static_cast<int64_t>(t.tv_nsec) / 1000000L; |
| 299 } |
| 300 |
| 301 |
296 void File::Stat(const char* name, int64_t* data) { | 302 void File::Stat(const char* name, int64_t* data) { |
297 struct stat st; | 303 struct stat st; |
298 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { | 304 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { |
299 if (S_ISREG(st.st_mode)) { | 305 if (S_ISREG(st.st_mode)) { |
300 data[kType] = kIsFile; | 306 data[kType] = kIsFile; |
301 } else if (S_ISDIR(st.st_mode)) { | 307 } else if (S_ISDIR(st.st_mode)) { |
302 data[kType] = kIsDirectory; | 308 data[kType] = kIsDirectory; |
303 } else if (S_ISLNK(st.st_mode)) { | 309 } else if (S_ISLNK(st.st_mode)) { |
304 data[kType] = kIsLink; | 310 data[kType] = kIsLink; |
305 } else { | 311 } else { |
306 data[kType] = kDoesNotExist; | 312 data[kType] = kDoesNotExist; |
307 } | 313 } |
308 data[kCreatedTime] = st.st_ctime; | 314 data[kCreatedTime] = TimespecToMilliseconds(st.st_ctim); |
309 data[kModifiedTime] = st.st_mtime; | 315 data[kModifiedTime] = TimespecToMilliseconds(st.st_mtim); |
310 data[kAccessedTime] = st.st_atime; | 316 data[kAccessedTime] = TimespecToMilliseconds(st.st_atim); |
311 data[kMode] = st.st_mode; | 317 data[kMode] = st.st_mode; |
312 data[kSize] = st.st_size; | 318 data[kSize] = st.st_size; |
313 } else { | 319 } else { |
314 data[kType] = kDoesNotExist; | 320 data[kType] = kDoesNotExist; |
315 } | 321 } |
316 } | 322 } |
317 | 323 |
318 | 324 |
319 time_t File::LastModified(const char* name) { | 325 time_t File::LastModified(const char* name) { |
320 struct stat st; | 326 struct stat st; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 return (file_1_info.st_ino == file_2_info.st_ino && | 428 return (file_1_info.st_ino == file_2_info.st_ino && |
423 file_1_info.st_dev == file_2_info.st_dev) ? | 429 file_1_info.st_dev == file_2_info.st_dev) ? |
424 File::kIdentical : | 430 File::kIdentical : |
425 File::kDifferent; | 431 File::kDifferent; |
426 } | 432 } |
427 | 433 |
428 } // namespace bin | 434 } // namespace bin |
429 } // namespace dart | 435 } // namespace dart |
430 | 436 |
431 #endif // defined(TARGET_OS_ANDROID) | 437 #endif // defined(TARGET_OS_ANDROID) |
OLD | NEW |