Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bb3a515f authored by Colin Cross's avatar Colin Cross
Browse files

Add GetExecutableDirectory to libbase

Tests will often want to get the executable directory in order to
find test data.

Test: out/host/linux-x86/nativetest64/libbase_tests/libbase_tests
Change-Id: Ica9d211bcd039fcf83a22fd494816abd01b97aa3
parent 58021d15
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -238,8 +238,11 @@ std::string GetExecutablePath() {
#endif
}

std::string Basename(const std::string& path) {
std::string GetExecutableDirectory() {
  return Dirname(GetExecutablePath());
}

std::string Basename(const std::string& path) {
  // Copy path because basename may modify the string passed in.
  std::string result(path);

+8 −0
Original line number Diff line number Diff line
@@ -159,6 +159,14 @@ TEST(file, Readlink) {
#endif
}

TEST(file, GetExecutableDirectory) {
  std::string path = android::base::GetExecutableDirectory();
  ASSERT_NE("", path);
  ASSERT_NE(android::base::GetExecutablePath(), path);
  ASSERT_EQ('/', path[0]);
  ASSERT_NE('/', path[path.size() - 1]);
}

TEST(file, GetExecutablePath) {
  ASSERT_NE("", android::base::GetExecutablePath());
}
+1 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ bool Readlink(const std::string& path, std::string* result);
#endif

std::string GetExecutablePath();
std::string GetExecutableDirectory();

// Like the regular basename and dirname, but thread-safe on all
// platforms and capable of correctly handling exotic Windows paths.