summaryrefslogtreecommitdiff
path: root/tools/bit/util.cpp
diff options
context:
space:
mode:
authorJoe Onorato <joeo@google.com>2019-02-27 20:42:37 -0500
committerJoe Onorato <joeo@google.com>2019-02-28 09:20:27 -0500
commit6c97f4908c99f26c7d59ac92bf74e7913a5333c8 (patch)
treeac9ad961c3f2e75304e9d552b919d83a1b64f888 /tools/bit/util.cpp
parentb953577b2784bebfc47ca8ad31fa55f2ea9808d1 (diff)
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
Diffstat (limited to 'tools/bit/util.cpp')
-rw-r--r--tools/bit/util.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/tools/bit/util.cpp b/tools/bit/util.cpp
index a502a9dbe736..63399d69a166 100644
--- a/tools/bit/util.cpp
+++ b/tools/bit/util.cpp
@@ -254,4 +254,42 @@ read_file(const string& filename)
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);
+ }
+}