OSDN Git Service

Use libbase for realpath and dirname
authorDimitry Ivanov <dimitry@google.com>
Thu, 16 Mar 2017 18:34:13 +0000 (11:34 -0700)
committerDimitry Ivanov <dimitry@google.com>
Thu, 16 Mar 2017 18:47:08 +0000 (11:47 -0700)
Test: run bionic-unit-tests
Bug: http://b/31396973
Change-Id: Ie8dc60348b9c57892a77be6a24dadb42241f6b62

tests/gtest_globals.cpp
tests/gtest_main.cpp
tests/utils.h

index 75c08b1..538a534 100644 (file)
 #include <gtest/gtest.h>
 #include "utils.h"
 
+#include <android-base/file.h>
+
 #include <string>
 
 static std::string init_testlib_root() {
   // Calculate ANDROID_DATA assuming the binary is in "$ANDROID_DATA/somedir/binary-dir/binary"
   std::string path = get_executable_path();
 
-  path = get_dirname(path.c_str());
+  path = android::base::Dirname(path);
   path += "/..";
 
   std::string out_path;
-  if (!get_realpath(path.c_str(), &out_path)) {
+  if (!android::base::Realpath(path.c_str(), &out_path)) {
     printf("Failed to get realpath for \"%s\"", path.c_str());
     abort();
   }
@@ -37,7 +39,7 @@ static std::string init_testlib_root() {
   out_path += "/bionic-loader-test-libs";
 
   std::string real_path;
-  if (!get_realpath(out_path, &real_path)) {
+  if (!android::base::Realpath(out_path, &real_path)) {
     printf("\"%s\": does not exists", out_path.c_str());
     abort();
   }
index aba93ba..5f28321 100644 (file)
@@ -56,25 +56,6 @@ const std::string& get_executable_path() {
   return g_executable_path;
 }
 
-bool get_realpath(const std::string& path, std::string* real_path) {
-  char realpath_buf[PATH_MAX];
-  if (realpath(path.c_str(), realpath_buf) != realpath_buf) {
-    return false;
-  }
-
-  *real_path = realpath_buf;
-  return true;
-}
-
-std::string get_dirname(const char* path) {
-#if defined(__BIONIC__)
-  return dirname(path);
-#else
-  // GLIBC does not have const char* dirname
-  return dirname(const_cast<char*>(path));
-#endif
-}
-
 int get_argc() {
   return g_argc;
 }
index 31974d0..fa85545 100644 (file)
@@ -143,11 +143,6 @@ static inline void AssertChildExited(int pid, int expected_exit_status) {
 // The absolute path to the executable
 const std::string& get_executable_path();
 
-// Get realpath
-bool get_realpath(const std::string& path, std::string* realpath);
-// Get dirname
-std::string get_dirname(const char* path);
-
 // Access to argc/argv/envp
 int get_argc();
 char** get_argv();