healthd: Fix readFromFile()

Not all readFromFile() callers pass an empty string. Make sure that
readFromFile() returns 0 (failure) if the *buf argument is not empty and
if reading fails.

Fixes: 3217c5c7d961 ("batterymonitor: simplify readFromFile and use std::string buffers")
Test: Compile-tested only.
Change-Id: I6f329491f8aa4a6d378eb7c3cbc17038eb6aa64d
Signed-off-by: Bart Van Assche <bvanassche@google.com>
diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp
index 45882a6..0566a67 100644
--- a/healthd/BatteryMonitor.cpp
+++ b/healthd/BatteryMonitor.cpp
@@ -228,6 +228,7 @@
 }
 
 int BatteryMonitor::readFromFile(const String8& path, std::string* buf) {
+    buf->clear();
     if (android::base::ReadFileToString(path.c_str(), buf)) {
         *buf = android::base::Trim(*buf);
     }