ART: Remove file_utils' ReadFileToString

Replace with libbase.

Test: mmma art
Change-Id: Id042f4879485e743e3dc7548434be1634370ee66
diff --git a/libartbase/base/file_utils.cc b/libartbase/base/file_utils.cc
index 5962ac1..d74cc14 100644
--- a/libartbase/base/file_utils.cc
+++ b/libartbase/base/file_utils.cc
@@ -75,25 +75,6 @@
 static constexpr const char* kAndroidConscryptRootEnvVar = "ANDROID_CONSCRYPT_ROOT";
 static constexpr const char* kAndroidConscryptApexDefaultPath = "/apex/com.android.conscrypt";
 
-bool ReadFileToString(const std::string& file_name, std::string* result) {
-  File file(file_name, O_RDONLY, false);
-  if (!file.IsOpened()) {
-    return false;
-  }
-
-  std::vector<char> buf(8 * KB);
-  while (true) {
-    int64_t n = TEMP_FAILURE_RETRY(read(file.Fd(), &buf[0], buf.size()));
-    if (n == -1) {
-      return false;
-    }
-    if (n == 0) {
-      return true;
-    }
-    result->append(&buf[0], n);
-  }
-}
-
 // Get the "root" directory containing the "lib" directory where this instance
 // of the libartbase library (which contains `GetRootContainingLibartbase`) is
 // located:
diff --git a/libartbase/base/file_utils.h b/libartbase/base/file_utils.h
index 7e97ab0..7e1923a 100644
--- a/libartbase/base/file_utils.h
+++ b/libartbase/base/file_utils.h
@@ -27,8 +27,6 @@
 
 namespace art {
 
-bool ReadFileToString(const std::string& file_name, std::string* result);
-
 // These methods return the Android Root, which is the historical location of
 // the Android "system" directory, containing the built Android artifacts. On
 // target, this is normally "/system". On host this is usually a directory under
diff --git a/runtime/native_stack_dump.cc b/runtime/native_stack_dump.cc
index 150fa78..ba5d141 100644
--- a/runtime/native_stack_dump.cc
+++ b/runtime/native_stack_dump.cc
@@ -39,6 +39,7 @@
 #include <sys/time.h>
 #include <sys/types.h>
 
+#include "android-base/file.h"
 #include "android-base/stringprintf.h"
 #include "android-base/strings.h"
 
@@ -418,7 +419,7 @@
 
   std::string kernel_stack_filename(StringPrintf("/proc/self/task/%d/stack", tid));
   std::string kernel_stack;
-  if (!ReadFileToString(kernel_stack_filename, &kernel_stack)) {
+  if (!android::base::ReadFileToString(kernel_stack_filename, &kernel_stack)) {
     os << prefix << "(couldn't read " << kernel_stack_filename << ")\n";
     return;
   }
diff --git a/runtime/signal_catcher.cc b/runtime/signal_catcher.cc
index 8da5fee..9b3de2a 100644
--- a/runtime/signal_catcher.cc
+++ b/runtime/signal_catcher.cc
@@ -27,6 +27,7 @@
 
 #include <sstream>
 
+#include <android-base/file.h>
 #include <android-base/stringprintf.h>
 
 #include "arch/instruction_set.h"
@@ -52,7 +53,7 @@
   // On Android, /proc/self/cmdline will have been rewritten to something like "system_server".
   // Note: The string "Cmd line:" is chosen to match the format used by debuggerd.
   std::string current_cmd_line;
-  if (ReadFileToString("/proc/self/cmdline", &current_cmd_line)) {
+  if (android::base::ReadFileToString("/proc/self/cmdline", &current_cmd_line)) {
     current_cmd_line.resize(current_cmd_line.find_last_not_of('\0') + 1);  // trim trailing '\0's
     std::replace(current_cmd_line.begin(), current_cmd_line.end(), '\0', ' ');
 
@@ -133,7 +134,7 @@
 
   if ((false)) {
     std::string maps;
-    if (ReadFileToString("/proc/self/maps", &maps)) {
+    if (android::base::ReadFileToString("/proc/self/maps", &maps)) {
       os << "/proc/self/maps:\n" << maps;
     }
   }
diff --git a/runtime/thread.cc b/runtime/thread.cc
index d6fce6a..1ad5b7e 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -35,6 +35,7 @@
 #include <list>
 #include <sstream>
 
+#include "android-base/file.h"
 #include "android-base/stringprintf.h"
 #include "android-base/strings.h"
 
@@ -1773,7 +1774,8 @@
   // 1:cpuacct,cpu:/
   // We want the third field from the line whose second field contains the "cpu" token.
   std::string cgroup_file;
-  if (!ReadFileToString(StringPrintf("/proc/self/task/%d/cgroup", tid), &cgroup_file)) {
+  if (!android::base::ReadFileToString(StringPrintf("/proc/self/task/%d/cgroup", tid),
+                                       &cgroup_file)) {
     return "";
   }
   std::vector<std::string> cgroup_lines;
@@ -1898,7 +1900,8 @@
 
   // Grab the scheduler stats for this thread.
   std::string scheduler_stats;
-  if (ReadFileToString(StringPrintf("/proc/self/task/%d/schedstat", tid), &scheduler_stats)
+  if (android::base::ReadFileToString(StringPrintf("/proc/self/task/%d/schedstat", tid),
+                                      &scheduler_stats)
       && !scheduler_stats.empty()) {
     scheduler_stats = android::base::Trim(scheduler_stats);  // Lose the trailing '\n'.
   } else {
diff --git a/test/137-cfi/cfi.cc b/test/137-cfi/cfi.cc
index b5210fd..aeb996c 100644
--- a/test/137-cfi/cfi.cc
+++ b/test/137-cfi/cfi.cc
@@ -25,6 +25,7 @@
 
 #include "jni.h"
 
+#include <android-base/file.h>
 #include <android-base/logging.h>
 #include <android-base/stringprintf.h>
 #include <backtrace/Backtrace.h>
@@ -62,7 +63,7 @@
 #if __linux__
   // Get our command line so that we can use it to start identical process.
   std::string cmdline;  // null-separated and null-terminated arguments.
-  ReadFileToString("/proc/self/cmdline", &cmdline);
+  android::base::ReadFileToString("/proc/self/cmdline", &cmdline);
   cmdline = cmdline + "--secondary" + '\0';  // Let the child know it is a helper.
 
   // Split the string into individual arguments suitable for execv.