From 75ea2fdb5c87f133a8e1b8da16f6091fb7d5321e Mon Sep 17 00:00:00 2001 From: chirantan Date: Tue, 7 Oct 2014 16:15:30 -0700 Subject: Refactor AppendToFile and WriteFileDescriptor - Unify the behavior of the windows and posix implementations of these functions. - Simplify the interface by having them just indicate success or failure instead of making callers deal with partial writes. BUG=418837 Signed-off-by: Chirantan Ekbote Review URL: https://codereview.chromium.org/614893004 Cr-Commit-Position: refs/heads/master@{#298604} --- chromeos/process_proxy/process_output_watcher_unittest.cc | 7 +++---- chromeos/process_proxy/process_proxy.cc | 6 ++---- 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'chromeos/process_proxy') diff --git a/chromeos/process_proxy/process_output_watcher_unittest.cc b/chromeos/process_proxy/process_output_watcher_unittest.cc index 0984ee2..f08a852 100644 --- a/chromeos/process_proxy/process_output_watcher_unittest.cc +++ b/chromeos/process_proxy/process_output_watcher_unittest.cc @@ -150,9 +150,8 @@ class ProcessOutputWatcherTest : public testing::Test { ssize_t test_size = test_str.length() * sizeof(*test_str.c_str()); if (test_cases[i].should_send_terminating_null) test_size += sizeof(*test_str.c_str()); - EXPECT_EQ(test_size, - base::WriteFileDescriptor(pt_pipe[1], test_str.c_str(), - test_size)); + EXPECT_TRUE(base::WriteFileDescriptor(pt_pipe[1], test_str.c_str(), + test_size)); run_loop.Run(); EXPECT_TRUE(expectations_.IsDone()); @@ -161,7 +160,7 @@ class ProcessOutputWatcherTest : public testing::Test { } // Send stop signal. It is not important which string we send. - EXPECT_EQ(1, base::WriteFileDescriptor(stop_pipe[1], "q", 1)); + EXPECT_TRUE(base::WriteFileDescriptor(stop_pipe[1], "q", 1)); EXPECT_NE(-1, IGNORE_EINTR(close(stop_pipe[1]))); EXPECT_NE(-1, IGNORE_EINTR(close(pt_pipe[1]))); diff --git a/chromeos/process_proxy/process_proxy.cc b/chromeos/process_proxy/process_proxy.cc index 881ea5a..b1021f4 100644 --- a/chromeos/process_proxy/process_proxy.cc +++ b/chromeos/process_proxy/process_proxy.cc @@ -160,10 +160,8 @@ bool ProcessProxy::Write(const std::string& text) { // We don't want to write '\0' to the pipe. size_t data_size = text.length() * sizeof(*text.c_str()); - int bytes_written = - base::WriteFileDescriptor(pt_pair_[PT_MASTER_FD], - text.c_str(), data_size); - return (bytes_written == static_cast(data_size)); + return base::WriteFileDescriptor( + pt_pair_[PT_MASTER_FD], text.c_str(), data_size); } bool ProcessProxy::OnTerminalResize(int width, int height) { -- cgit v1.1