From 5b2cd3a358dd45d28d794858f29f98b1d7d9d9df Mon Sep 17 00:00:00 2001 From: Dimitry Ivanov Date: Thu, 16 Mar 2017 11:34:13 -0700 Subject: [PATCH] Use libbase for realpath and dirname Test: run bionic-unit-tests Bug: http://b/31396973 Change-Id: Ie8dc60348b9c57892a77be6a24dadb42241f6b62 --- tests/gtest_globals.cpp | 8 +++++--- tests/gtest_main.cpp | 19 ------------------- tests/utils.h | 5 ----- 3 files changed, 5 insertions(+), 27 deletions(-) diff --git a/tests/gtest_globals.cpp b/tests/gtest_globals.cpp index 75c08b1da..538a53456 100644 --- a/tests/gtest_globals.cpp +++ b/tests/gtest_globals.cpp @@ -19,17 +19,19 @@ #include #include "utils.h" +#include + #include 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(); } diff --git a/tests/gtest_main.cpp b/tests/gtest_main.cpp index aba93ba8e..5f2832189 100644 --- a/tests/gtest_main.cpp +++ b/tests/gtest_main.cpp @@ -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(path)); -#endif -} - int get_argc() { return g_argc; } diff --git a/tests/utils.h b/tests/utils.h index 31974d05e..fa855456c 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -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(); -- 2.11.0