Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: runtime/bin/file_win.cc

Issue 1800863002: Cleanup in //runtime/bin (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Windows fixes Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <WinIoCtl.h> // NOLINT 15 #include <WinIoCtl.h> // NOLINT
16 16
17 #include "bin/builtin.h" 17 #include "bin/builtin.h"
18 #include "bin/log.h" 18 #include "bin/log.h"
19 #include "bin/utils.h" 19 #include "bin/utils.h"
20 #include "bin/utils_win.h" 20 #include "bin/utils_win.h"
21 #include "platform/utils.h" 21 #include "platform/utils.h"
22 22
23
24 namespace dart { 23 namespace dart {
25 namespace bin { 24 namespace bin {
26 25
27 class FileHandle { 26 class FileHandle {
28 public: 27 public:
29 explicit FileHandle(int fd) : fd_(fd) { } 28 explicit FileHandle(int fd) : fd_(fd) { }
30 ~FileHandle() { } 29 ~FileHandle() { }
31 int fd() const { return fd_; } 30 int fd() const { return fd_; }
32 void set_fd(int fd) { fd_ = fd; } 31 void set_fd(int fd) { fd_ = fd; }
33 32
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 102
104 103
105 bool File::Flush() { 104 bool File::Flush() {
106 ASSERT(handle_->fd()); 105 ASSERT(handle_->fd());
107 return _commit(handle_->fd()) != -1; 106 return _commit(handle_->fd()) != -1;
108 } 107 }
109 108
110 109
111 bool File::Lock(File::LockType lock, int64_t start, int64_t end) { 110 bool File::Lock(File::LockType lock, int64_t start, int64_t end) {
112 ASSERT(handle_->fd() >= 0); 111 ASSERT(handle_->fd() >= 0);
113 ASSERT(end == -1 || end > start); 112 ASSERT((end == -1) || (end > start));
114 HANDLE handle = reinterpret_cast<HANDLE>(_get_osfhandle(handle_->fd())); 113 HANDLE handle = reinterpret_cast<HANDLE>(_get_osfhandle(handle_->fd()));
115 OVERLAPPED overlapped; 114 OVERLAPPED overlapped;
116 ZeroMemory(&overlapped, sizeof(OVERLAPPED)); 115 ZeroMemory(&overlapped, sizeof(OVERLAPPED));
117 116
118 overlapped.Offset = Utils::Low32Bits(start); 117 overlapped.Offset = Utils::Low32Bits(start);
119 overlapped.OffsetHigh = Utils::High32Bits(start); 118 overlapped.OffsetHigh = Utils::High32Bits(start);
120 119
121 int64_t length = end == -1 ? 0 : end - start; 120 int64_t length = end == -1 ? 0 : end - start;
122 if (length == 0) { 121 if (length == 0) {
123 length = kMaxInt64; 122 length = kMaxInt64;
124 } 123 }
125 int32_t length_low = Utils::Low32Bits(length); 124 int32_t length_low = Utils::Low32Bits(length);
126 int32_t length_high = Utils::High32Bits(length); 125 int32_t length_high = Utils::High32Bits(length);
127 126
128
129 BOOL rc; 127 BOOL rc;
130 switch (lock) { 128 switch (lock) {
131 case File::kLockUnlock: 129 case File::kLockUnlock:
132 rc = UnlockFileEx(handle, 0, length_low, length_high, &overlapped); 130 rc = UnlockFileEx(handle, 0, length_low, length_high, &overlapped);
133 break; 131 break;
134 case File::kLockShared: 132 case File::kLockShared:
135 case File::kLockExclusive: { 133 case File::kLockExclusive: {
136 DWORD flags = LOCKFILE_FAIL_IMMEDIATELY; 134 DWORD flags = LOCKFILE_FAIL_IMMEDIATELY;
137 if (lock == File::kLockExclusive) { 135 if (lock == File::kLockExclusive) {
138 flags |= LOCKFILE_EXCLUSIVE_LOCK; 136 flags |= LOCKFILE_EXCLUSIVE_LOCK;
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 } 540 }
543 return -1; 541 return -1;
544 } 542 }
545 543
546 544
547 bool File::IsAbsolutePath(const char* pathname) { 545 bool File::IsAbsolutePath(const char* pathname) {
548 // Should we consider network paths? 546 // Should we consider network paths?
549 if (pathname == NULL) { 547 if (pathname == NULL) {
550 return false; 548 return false;
551 } 549 }
552 return (strlen(pathname) > 2) && 550 return ((strlen(pathname) > 2) &&
553 (pathname[1] == ':') && 551 (pathname[1] == ':') &&
554 (pathname[2] == '\\' || pathname[2] == '/'); 552 ((pathname[2] == '\\') || (pathname[2] == '/')));
555 } 553 }
556 554
557 555
558 const char* File::GetCanonicalPath(const char* pathname) { 556 const char* File::GetCanonicalPath(const char* pathname) {
559 const wchar_t* system_name = StringUtilsWin::Utf8ToWide(pathname); 557 const wchar_t* system_name = StringUtilsWin::Utf8ToWide(pathname);
560 HANDLE file_handle = CreateFileW( 558 HANDLE file_handle = CreateFileW(
561 system_name, 559 system_name,
562 0, 560 0,
563 FILE_SHARE_READ, 561 FILE_SHARE_READ,
564 NULL, 562 NULL,
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 return kIdentical; 685 return kIdentical;
688 } else { 686 } else {
689 return kDifferent; 687 return kDifferent;
690 } 688 }
691 } 689 }
692 690
693 } // namespace bin 691 } // namespace bin
694 } // namespace dart 692 } // namespace dart
695 693
696 #endif // defined(TARGET_OS_WINDOWS) 694 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698