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

Unified Diff: runtime/bin/file_android.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/eventhandler_win.cc ('k') | runtime/bin/file_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file_android.cc
diff --git a/runtime/bin/file_android.cc b/runtime/bin/file_android.cc
index b00e22de3bbc980d42319143dce10c7478bc9ecd..6c740c59fdf68b80b992f95ce39894e1021a4f2b 100644
--- a/runtime/bin/file_android.cc
+++ b/runtime/bin/file_android.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/eventhandler_win.cc ('k') | runtime/bin/file_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698