From 6c97f4908c99f26c7d59ac92bf74e7913a5333c8 Mon Sep 17 00:00:00 2001 From: Joe Onorato Date: Wed, 27 Feb 2019 20:42:37 -0500 Subject: 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 --- tools/bit/util.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'tools/bit/util.cpp') 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); + } +} -- cgit v1.2.3-59-g8ed1b