Merge "Use libbase for realpath and dirname"

This commit is contained in:
Treehugger Robot 2017-03-16 20:36:56 +00:00 committed by Gerrit Code Review
commit e0561cb0c9
3 changed files with 5 additions and 27 deletions

View File

@ -19,17 +19,19 @@
#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();
}

View 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;
}

View 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();