Make bit able to run gtest native tests.
The output parsing isn't ideal, so these are a bit more spammy
than I'd like, but at least they build, install and run without
the manual glop.
Test: bit incidentd_test
Change-Id: I3c34a4ebbf661f612b4b0f8b4e05cade8669b5a6
diff --git a/tools/bit/util.cpp b/tools/bit/util.cpp
index a502a9d..63399d6 100644
--- a/tools/bit/util.cpp
+++ b/tools/bit/util.cpp
@@ -254,4 +254,42 @@
return result;
}
+bool
+is_executable(const string& filename)
+{
+ int err;
+ struct stat st;
+ err = stat(filename.c_str(), &st);
+ if (err != 0) {
+ return false;
+ }
+
+ return (st.st_mode & S_IXUSR) != 0;
+}
+
+string
+dirname(const string& filename)
+{
+ size_t slash = filename.rfind('/');
+ if (slash == string::npos) {
+ return "";
+ } else if (slash == 0) {
+ return "/";
+ } else {
+ return string(filename, 0, slash);
+ }
+}
+
+string
+leafname(const string& filename)
+{
+ size_t slash = filename.rfind('/');
+ if (slash == string::npos) {
+ return filename;
+ } else if (slash == filename.length() - 1) {
+ return "";
+ } else {
+ return string(filename, slash + 1);
+ }
+}