#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();
}
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();
}
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;
}
// 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();