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_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
7 | 7 |
8 #include "bin/file.h" | 8 #include "bin/file.h" |
9 | 9 |
10 #include <fcntl.h> // NOLINT | 10 #include <fcntl.h> // NOLINT |
11 #include <io.h> // NOLINT | 11 #include <io.h> // NOLINT |
12 #include <stdio.h> // NOLINT | 12 #include <stdio.h> // NOLINT |
13 #include <string.h> // NOLINT | 13 #include <string.h> // NOLINT |
14 #include <sys/stat.h> // NOLINT | 14 #include <sys/stat.h> // NOLINT |
| 15 #include <sys/utime.h> // NOLINT |
15 #include <WinIoCtl.h> // NOLINT | 16 #include <WinIoCtl.h> // NOLINT |
16 | 17 |
17 #include "bin/builtin.h" | 18 #include "bin/builtin.h" |
18 #include "bin/log.h" | 19 #include "bin/log.h" |
19 #include "bin/utils.h" | 20 #include "bin/utils.h" |
20 #include "bin/utils_win.h" | 21 #include "bin/utils_win.h" |
21 #include "platform/utils.h" | 22 #include "platform/utils.h" |
22 | 23 |
23 namespace dart { | 24 namespace dart { |
24 namespace bin { | 25 namespace bin { |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 fd = _fileno(stderr); | 249 fd = _fileno(stderr); |
249 break; | 250 break; |
250 default: | 251 default: |
251 UNREACHABLE(); | 252 UNREACHABLE(); |
252 } | 253 } |
253 _setmode(fd, _O_BINARY); | 254 _setmode(fd, _O_BINARY); |
254 return new File(new FileHandle(fd)); | 255 return new File(new FileHandle(fd)); |
255 } | 256 } |
256 | 257 |
257 | 258 |
| 259 static bool StatHelper(wchar_t* path, struct __stat64* st) { |
| 260 int stat_status = _wstat64(path, st); |
| 261 if (stat_status != 0) { |
| 262 return false; |
| 263 } |
| 264 if ((st->st_mode & S_IFMT) != S_IFREG) { |
| 265 SetLastError(ERROR_NOT_SUPPORTED); |
| 266 return false; |
| 267 } |
| 268 return true; |
| 269 } |
| 270 |
| 271 |
258 bool File::Exists(const char* name) { | 272 bool File::Exists(const char* name) { |
259 struct __stat64 st; | 273 struct __stat64 st; |
260 Utf8ToWideScope system_name(name); | 274 Utf8ToWideScope system_name(name); |
261 bool stat_status = _wstat64(system_name.wide(), &st); | 275 return StatHelper(system_name.wide(), &st); |
262 if (stat_status == 0) { | |
263 return ((st.st_mode & S_IFMT) == S_IFREG); | |
264 } else { | |
265 return false; | |
266 } | |
267 } | 276 } |
268 | 277 |
269 | 278 |
270 bool File::Create(const char* name) { | 279 bool File::Create(const char* name) { |
271 Utf8ToWideScope system_name(name); | 280 Utf8ToWideScope system_name(name); |
272 int fd = _wopen(system_name.wide(), O_RDONLY | O_CREAT, 0666); | 281 int fd = _wopen(system_name.wide(), O_RDONLY | O_CREAT, 0666); |
273 if (fd < 0) { | 282 if (fd < 0) { |
274 return false; | 283 return false; |
275 } | 284 } |
276 return (close(fd) == 0); | 285 return (close(fd) == 0); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 } else { | 444 } else { |
436 SetLastError(ERROR_FILE_NOT_FOUND); | 445 SetLastError(ERROR_FILE_NOT_FOUND); |
437 } | 446 } |
438 return false; | 447 return false; |
439 } | 448 } |
440 | 449 |
441 | 450 |
442 int64_t File::LengthFromPath(const char* name) { | 451 int64_t File::LengthFromPath(const char* name) { |
443 struct __stat64 st; | 452 struct __stat64 st; |
444 Utf8ToWideScope system_name(name); | 453 Utf8ToWideScope system_name(name); |
445 int stat_status = _wstat64(system_name.wide(), &st); | 454 if (!StatHelper(system_name.wide(), &st)) { |
446 if (stat_status == 0) { | 455 return -1; |
447 if ((st.st_mode & S_IFMT) == S_IFREG) { | |
448 return st.st_size; | |
449 } else { | |
450 // ERROR_DIRECTORY_NOT_SUPPORTED is not always in the message table. | |
451 SetLastError(ERROR_NOT_SUPPORTED); | |
452 } | |
453 } | 456 } |
454 return -1; | 457 return st.st_size; |
455 } | 458 } |
456 | 459 |
457 | 460 |
458 const char* File::LinkTarget(const char* pathname) { | 461 const char* File::LinkTarget(const char* pathname) { |
459 const wchar_t* name = StringUtilsWin::Utf8ToWide(pathname); | 462 const wchar_t* name = StringUtilsWin::Utf8ToWide(pathname); |
460 HANDLE dir_handle = CreateFileW( | 463 HANDLE dir_handle = CreateFileW( |
461 name, GENERIC_READ, | 464 name, GENERIC_READ, |
462 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, | 465 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, |
463 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, | 466 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, |
464 NULL); | 467 NULL); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 data[kAccessedTime] = st.st_atime * 1000; | 535 data[kAccessedTime] = st.st_atime * 1000; |
533 data[kMode] = st.st_mode; | 536 data[kMode] = st.st_mode; |
534 data[kSize] = st.st_size; | 537 data[kSize] = st.st_size; |
535 } else { | 538 } else { |
536 data[kType] = File::kDoesNotExist; | 539 data[kType] = File::kDoesNotExist; |
537 } | 540 } |
538 } | 541 } |
539 } | 542 } |
540 | 543 |
541 | 544 |
| 545 time_t File::LastAccessed(const char* name) { |
| 546 struct __stat64 st; |
| 547 Utf8ToWideScope system_name(name); |
| 548 if (!StatHelper(system_name.wide(), &st)) { |
| 549 return -1; |
| 550 } |
| 551 return st.st_atime; |
| 552 } |
| 553 |
| 554 |
542 time_t File::LastModified(const char* name) { | 555 time_t File::LastModified(const char* name) { |
543 struct __stat64 st; | 556 struct __stat64 st; |
544 Utf8ToWideScope system_name(name); | 557 Utf8ToWideScope system_name(name); |
545 int stat_status = _wstat64(system_name.wide(), &st); | 558 if (!StatHelper(system_name.wide(), &st)) { |
546 if (stat_status == 0) { | 559 return -1; |
547 if ((st.st_mode & S_IFMT) == S_IFREG) { | |
548 return st.st_mtime; | |
549 } else { | |
550 // ERROR_DIRECTORY_NOT_SUPPORTED is not always in the message table. | |
551 SetLastError(ERROR_NOT_SUPPORTED); | |
552 } | |
553 } | 560 } |
554 return -1; | 561 return st.st_mtime; |
555 } | 562 } |
556 | 563 |
557 | 564 |
| 565 bool File::SetLastAccessed(const char* name, int64_t millis) { |
| 566 // First get the current times. |
| 567 struct __stat64 st; |
| 568 Utf8ToWideScope system_name(name); |
| 569 if (!StatHelper(system_name.wide(), &st)) { |
| 570 return false; |
| 571 } |
| 572 |
| 573 // Set the new time: |
| 574 struct __utimbuf64 times; |
| 575 times.actime = millis / kMillisecondsPerSecond; |
| 576 times.modtime = st.st_mtime; |
| 577 return _wutime64(system_name.wide(), ×) == 0; |
| 578 } |
| 579 |
| 580 |
| 581 bool File::SetLastModified(const char* name, int64_t millis) { |
| 582 // First get the current times. |
| 583 struct __stat64 st; |
| 584 Utf8ToWideScope system_name(name); |
| 585 if (!StatHelper(system_name.wide(), &st)) { |
| 586 return false; |
| 587 } |
| 588 |
| 589 // Set the new time: |
| 590 struct __utimbuf64 times; |
| 591 times.actime = st.st_atime; |
| 592 times.modtime = millis / kMillisecondsPerSecond; |
| 593 return _wutime64(system_name.wide(), ×) == 0; |
| 594 } |
| 595 |
| 596 |
558 bool File::IsAbsolutePath(const char* pathname) { | 597 bool File::IsAbsolutePath(const char* pathname) { |
559 // Should we consider network paths? | 598 // Should we consider network paths? |
560 if (pathname == NULL) { | 599 if (pathname == NULL) { |
561 return false; | 600 return false; |
562 } | 601 } |
563 return ((strlen(pathname) > 2) && (pathname[1] == ':') && | 602 return ((strlen(pathname) > 2) && (pathname[1] == ':') && |
564 ((pathname[2] == '\\') || (pathname[2] == '/'))); | 603 ((pathname[2] == '\\') || (pathname[2] == '/'))); |
565 } | 604 } |
566 | 605 |
567 | 606 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 return kIdentical; | 720 return kIdentical; |
682 } else { | 721 } else { |
683 return kDifferent; | 722 return kDifferent; |
684 } | 723 } |
685 } | 724 } |
686 | 725 |
687 } // namespace bin | 726 } // namespace bin |
688 } // namespace dart | 727 } // namespace dart |
689 | 728 |
690 #endif // defined(TARGET_OS_WINDOWS) | 729 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |