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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/eventhandler_win.cc ('k') | runtime/bin/file_linux.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_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
7 7
8 #include "bin/file.h" 8 #include "bin/file.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
(...skipping 20 matching lines...) Expand all
31 void set_fd(int fd) { fd_ = fd; } 31 void set_fd(int fd) { fd_ = fd; }
32 32
33 private: 33 private:
34 int fd_; 34 int fd_;
35 35
36 DISALLOW_COPY_AND_ASSIGN(FileHandle); 36 DISALLOW_COPY_AND_ASSIGN(FileHandle);
37 }; 37 };
38 38
39 39
40 File::~File() { 40 File::~File() {
41 // Close the file (unless it's a standard stream). 41 Close();
42 if (handle_->fd() > STDERR_FILENO) {
43 Close();
44 }
45 delete handle_; 42 delete handle_;
46 } 43 }
47 44
48 45
49 void File::Close() { 46 void File::Close() {
50 ASSERT(handle_->fd() >= 0); 47 ASSERT(handle_->fd() >= 0);
51 int err = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(handle_->fd())); 48 if (handle_->fd() == STDOUT_FILENO) {
52 if (err != 0) { 49 // If stdout, redirect fd to /dev/null.
53 const int kBufferSize = 1024; 50 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY));
54 char error_message[kBufferSize]; 51 ASSERT(null_fd >= 0);
55 strerror_r(errno, error_message, kBufferSize); 52 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, handle_->fd()));
56 Log::PrintErr("%s\n", error_message); 53 VOID_TEMP_FAILURE_RETRY(close(null_fd));
54 } else {
55 int err = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(handle_->fd()));
56 if (err != 0) {
57 const int kBufferSize = 1024;
58 char error_message[kBufferSize];
59 strerror_r(errno, error_message, kBufferSize);
60 Log::PrintErr("%s\n", error_message);
61 }
57 } 62 }
58 handle_->set_fd(kClosedFd); 63 handle_->set_fd(kClosedFd);
59 } 64 }
60 65
61 66
62 bool File::IsClosed() { 67 bool File::IsClosed() {
63 return handle_->fd() == kClosedFd; 68 return handle_->fd() == kClosedFd;
64 } 69 }
65 70
66 71
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 return (file_1_info.st_ino == file_2_info.st_ino && 430 return (file_1_info.st_ino == file_2_info.st_ino &&
426 file_1_info.st_dev == file_2_info.st_dev) ? 431 file_1_info.st_dev == file_2_info.st_dev) ?
427 File::kIdentical : 432 File::kIdentical :
428 File::kDifferent; 433 File::kDifferent;
429 } 434 }
430 435
431 } // namespace bin 436 } // namespace bin
432 } // namespace dart 437 } // namespace dart
433 438
434 #endif // defined(TARGET_OS_ANDROID) 439 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« 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