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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/file_macos.cc ('k') | runtime/bin/main.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file_win.cc
diff --git a/runtime/bin/file_win.cc b/runtime/bin/file_win.cc
index 32905f46c29617b3c1664a5bc0f1fc8022e010e8..b43ae0c772334a51ae66b2a39123d0514644fcd9 100644
--- a/runtime/bin/file_win.cc
+++ b/runtime/bin/file_win.cc
@@ -37,19 +37,23 @@ class FileHandle {
File::~File() {
- // Close the file (unless it's a standard stream).
- if (handle_->fd() > 2) {
- Close();
- }
+ Close();
delete handle_;
}
void File::Close() {
ASSERT(handle_->fd() >= 0);
- int err = close(handle_->fd());
- if (err != 0) {
- Log::PrintErr("%s\n", strerror(errno));
+ if (handle_->fd() == _fileno(stdout)) {
+ int fd = _open("NUL", _O_WRONLY);
+ ASSERT(fd >= 0);
+ _dup2(fd, handle_->fd());
+ close(fd);
+ } else {
+ int err = close(handle_->fd());
+ if (err != 0) {
+ Log::PrintErr("%s\n", strerror(errno));
+ }
}
handle_->set_fd(kClosedFd);
}
@@ -131,8 +135,17 @@ File* File::Open(const char* name, FileOpenMode mode) {
File* File::OpenStdio(int fd) {
- UNREACHABLE();
- return NULL;
+ switch (fd) {
+ case 1:
+ fd = _fileno(stdout);
+ break;
+ case 2:
+ fd = _fileno(stderr);
+ break;
+ default:
+ UNREACHABLE();
+ }
+ return new File(new FileHandle(fd));
}
« 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