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_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 285 |
286 int64_t File::LengthFromPath(const char* name) { | 286 int64_t File::LengthFromPath(const char* name) { |
287 struct stat64 st; | 287 struct stat64 st; |
288 if (NO_RETRY_EXPECTED(stat64(name, &st)) == 0) { | 288 if (NO_RETRY_EXPECTED(stat64(name, &st)) == 0) { |
289 return st.st_size; | 289 return st.st_size; |
290 } | 290 } |
291 return -1; | 291 return -1; |
292 } | 292 } |
293 | 293 |
294 | 294 |
| 295 static int64_t TimespecToMilliseconds(const struct timespec& t) { |
| 296 return static_cast<int64_t>(t.tv_sec) * 1000L + |
| 297 static_cast<int64_t>(t.tv_nsec) / 1000000L; |
| 298 } |
| 299 |
| 300 |
295 void File::Stat(const char* name, int64_t* data) { | 301 void File::Stat(const char* name, int64_t* data) { |
296 struct stat64 st; | 302 struct stat64 st; |
297 if (NO_RETRY_EXPECTED(stat64(name, &st)) == 0) { | 303 if (NO_RETRY_EXPECTED(stat64(name, &st)) == 0) { |
298 if (S_ISREG(st.st_mode)) { | 304 if (S_ISREG(st.st_mode)) { |
299 data[kType] = kIsFile; | 305 data[kType] = kIsFile; |
300 } else if (S_ISDIR(st.st_mode)) { | 306 } else if (S_ISDIR(st.st_mode)) { |
301 data[kType] = kIsDirectory; | 307 data[kType] = kIsDirectory; |
302 } else if (S_ISLNK(st.st_mode)) { | 308 } else if (S_ISLNK(st.st_mode)) { |
303 data[kType] = kIsLink; | 309 data[kType] = kIsLink; |
304 } else { | 310 } else { |
305 data[kType] = kDoesNotExist; | 311 data[kType] = kDoesNotExist; |
306 } | 312 } |
307 data[kCreatedTime] = st.st_ctime; | 313 data[kCreatedTime] = TimespecToMilliseconds(st.st_ctim); |
308 data[kModifiedTime] = st.st_mtime; | 314 data[kModifiedTime] = TimespecToMilliseconds(st.st_mtim); |
309 data[kAccessedTime] = st.st_atime; | 315 data[kAccessedTime] = TimespecToMilliseconds(st.st_atim); |
310 data[kMode] = st.st_mode; | 316 data[kMode] = st.st_mode; |
311 data[kSize] = st.st_size; | 317 data[kSize] = st.st_size; |
312 } else { | 318 } else { |
313 data[kType] = kDoesNotExist; | 319 data[kType] = kDoesNotExist; |
314 } | 320 } |
315 } | 321 } |
316 | 322 |
317 | 323 |
318 time_t File::LastModified(const char* name) { | 324 time_t File::LastModified(const char* name) { |
319 struct stat64 st; | 325 struct stat64 st; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 return (file_1_info.st_ino == file_2_info.st_ino && | 421 return (file_1_info.st_ino == file_2_info.st_ino && |
416 file_1_info.st_dev == file_2_info.st_dev) ? | 422 file_1_info.st_dev == file_2_info.st_dev) ? |
417 File::kIdentical : | 423 File::kIdentical : |
418 File::kDifferent; | 424 File::kDifferent; |
419 } | 425 } |
420 | 426 |
421 } // namespace bin | 427 } // namespace bin |
422 } // namespace dart | 428 } // namespace dart |
423 | 429 |
424 #endif // defined(TARGET_OS_LINUX) | 430 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |