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

Unified Diff: runtime/bin/file_macos.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_linux.cc ('k') | runtime/bin/file_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file_macos.cc
diff --git a/runtime/bin/file_macos.cc b/runtime/bin/file_macos.cc
index 6f704bfa59a27d6c82fc6c41f584ea2a6b3aba8e..e573f6cefdb3c396fb8dbb2ca5f008b213b49030 100644
--- a/runtime/bin/file_macos.cc
+++ b/runtime/bin/file_macos.cc
@@ -38,22 +38,27 @@ class FileHandle {
File::~File() {
- // Close the file (unless it's a standard stream).
- if (handle_->fd() > STDERR_FILENO) {
- Close();
- }
+ Close();
delete handle_;
}
void File::Close() {
ASSERT(handle_->fd() >= 0);
- int err = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(handle_->fd()));
- if (err != 0) {
- const int kBufferSize = 1024;
- char error_message[kBufferSize];
- strerror_r(errno, error_message, kBufferSize);
- Log::PrintErr("%s\n", error_message);
+ if (handle_->fd() == STDOUT_FILENO) {
+ // If stdout, redirect fd to /dev/null.
+ int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY));
+ ASSERT(null_fd >= 0);
+ VOID_TEMP_FAILURE_RETRY(dup2(null_fd, handle_->fd()));
+ VOID_TEMP_FAILURE_RETRY(close(null_fd));
+ } else {
+ int err = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(handle_->fd()));
+ if (err != 0) {
+ const int kBufferSize = 1024;
+ char error_message[kBufferSize];
+ strerror_r(errno, error_message, kBufferSize);
+ Log::PrintErr("%s\n", error_message);
+ }
}
handle_->set_fd(kClosedFd);
}
« no previous file with comments | « runtime/bin/file_linux.cc ('k') | runtime/bin/file_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698