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

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

Issue 154273003: Make std* blocking file-descriptors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update with bug. Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « runtime/bin/file_macos.cc ('k') | runtime/bin/main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 19 matching lines...) Expand all
30 void set_fd(int fd) { fd_ = fd; } 30 void set_fd(int fd) { fd_ = fd; }
31 31
32 private: 32 private:
33 int fd_; 33 int fd_;
34 34
35 DISALLOW_COPY_AND_ASSIGN(FileHandle); 35 DISALLOW_COPY_AND_ASSIGN(FileHandle);
36 }; 36 };
37 37
38 38
39 File::~File() { 39 File::~File() {
40 // Close the file (unless it's a standard stream). 40 Close();
41 if (handle_->fd() > 2) {
42 Close();
43 }
44 delete handle_; 41 delete handle_;
45 } 42 }
46 43
47 44
48 void File::Close() { 45 void File::Close() {
49 ASSERT(handle_->fd() >= 0); 46 ASSERT(handle_->fd() >= 0);
50 int err = close(handle_->fd()); 47 if (handle_->fd() == _fileno(stdout)) {
51 if (err != 0) { 48 int fd = _open("NUL", _O_WRONLY);
52 Log::PrintErr("%s\n", strerror(errno)); 49 ASSERT(fd >= 0);
50 _dup2(fd, handle_->fd());
51 close(fd);
52 } else {
53 int err = close(handle_->fd());
54 if (err != 0) {
55 Log::PrintErr("%s\n", strerror(errno));
56 }
53 } 57 }
54 handle_->set_fd(kClosedFd); 58 handle_->set_fd(kClosedFd);
55 } 59 }
56 60
57 61
58 bool File::IsClosed() { 62 bool File::IsClosed() {
59 return handle_->fd() == kClosedFd; 63 return handle_->fd() == kClosedFd;
60 } 64 }
61 65
62 66
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 int64_t position = _lseeki64(fd, 0, SEEK_END); 128 int64_t position = _lseeki64(fd, 0, SEEK_END);
125 if (position < 0) { 129 if (position < 0) {
126 return NULL; 130 return NULL;
127 } 131 }
128 } 132 }
129 return new File(new FileHandle(fd)); 133 return new File(new FileHandle(fd));
130 } 134 }
131 135
132 136
133 File* File::OpenStdio(int fd) { 137 File* File::OpenStdio(int fd) {
134 UNREACHABLE(); 138 switch (fd) {
135 return NULL; 139 case 1:
140 fd = _fileno(stdout);
141 break;
142 case 2:
143 fd = _fileno(stderr);
144 break;
145 default:
146 UNREACHABLE();
147 }
148 return new File(new FileHandle(fd));
136 } 149 }
137 150
138 151
139 bool File::Exists(const char* name) { 152 bool File::Exists(const char* name) {
140 struct __stat64 st; 153 struct __stat64 st;
141 const wchar_t* system_name = StringUtils::Utf8ToWide(name); 154 const wchar_t* system_name = StringUtils::Utf8ToWide(name);
142 bool stat_status = _wstat64(system_name, &st); 155 bool stat_status = _wstat64(system_name, &st);
143 free(const_cast<wchar_t*>(system_name)); 156 free(const_cast<wchar_t*>(system_name));
144 if (stat_status == 0) { 157 if (stat_status == 0) {
145 return ((st.st_mode & S_IFMT) == S_IFREG); 158 return ((st.st_mode & S_IFMT) == S_IFREG);
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 return kIdentical; 640 return kIdentical;
628 } else { 641 } else {
629 return kDifferent; 642 return kDifferent;
630 } 643 }
631 } 644 }
632 645
633 } // namespace bin 646 } // namespace bin
634 } // namespace dart 647 } // namespace dart
635 648
636 #endif // defined(TARGET_OS_WINDOWS) 649 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW
« no previous file with comments | « runtime/bin/file_macos.cc ('k') | runtime/bin/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698