Merge "Atrace:use ReadFileToString to read file"
am: 3cebac7

* commit '3cebac75a29cabec5024a7316117f401b60cc248':
  Atrace:use ReadFileToString to read file

Change-Id: Ib5b32935ea42321dc3566655cb875ed04161b7cb
diff --git a/cmds/atrace/Android.mk b/cmds/atrace/Android.mk
index a787e95..bfb3838 100644
--- a/cmds/atrace/Android.mk
+++ b/cmds/atrace/Android.mk
@@ -16,6 +16,7 @@
     libcutils \
     libutils \
     libz \
+    libbase
 
 LOCAL_INIT_RC := atrace.rc
 
diff --git a/cmds/atrace/atrace.cpp b/cmds/atrace/atrace.cpp
index 6549dde..d99b6fe 100644
--- a/cmds/atrace/atrace.cpp
+++ b/cmds/atrace/atrace.cpp
@@ -39,6 +39,7 @@
 #include <utils/Timers.h>
 #include <utils/Tokenizer.h>
 #include <utils/Trace.h>
+#include <android-base/file.h>
 
 using namespace android;
 
@@ -525,24 +526,14 @@
 // kernel.
 static bool verifyKernelTraceFuncs(const char* funcs)
 {
-    int fd = open(k_ftraceFilterPath, O_RDONLY);
-    if (fd == -1) {
-        fprintf(stderr, "error opening %s: %s (%d)\n", k_ftraceFilterPath,
+    std::string buf;
+    if (!android::base::ReadFileToString(k_ftraceFilterPath, &buf)) {
+         fprintf(stderr, "error opening %s: %s (%d)\n", k_ftraceFilterPath,
             strerror(errno), errno);
-        return false;
+         return false;
     }
 
-    char buf[4097];
-    ssize_t n = read(fd, buf, 4096);
-    close(fd);
-    if (n == -1) {
-        fprintf(stderr, "error reading %s: %s (%d)\n", k_ftraceFilterPath,
-            strerror(errno), errno);
-        return false;
-    }
-
-    buf[n] = '\0';
-    String8 funcList = String8::format("\n%s", buf);
+    String8 funcList = String8::format("\n%s",buf.c_str());
 
     // Make sure that every function listed in funcs is in the list we just
     // read from the kernel, except for wildcard inputs.
@@ -562,7 +553,6 @@
         func = strtok(NULL, ",");
     }
     free(myFuncs);
-
     return ok;
 }