From: Joel Rosdahl Date: Fri, 31 Jul 2020 17:28:48 +0000 (+0200) Subject: C++-ify is_full_path X-Git-Tag: v4.0~244 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=54a3e144b9bf18faa1aa409cfb9adc23e7cd5f49;p=thirdparty%2Fccache.git C++-ify is_full_path --- diff --git a/src/Util.hpp b/src/Util.hpp index 62b9e49fc..8b57199ce 100644 --- a/src/Util.hpp +++ b/src/Util.hpp @@ -273,6 +273,18 @@ is_dir_separator(char ch) ; } +// Return whether `path` is a full path. +inline bool +is_full_path(nonstd::string_view path) +{ +#ifdef _WIN32 + if (path.find('\\') != nonstd::string_view::npos) { + return true; + } +#endif + return path.find('/') != nonstd::string_view::npos; +} + // Return whether `path` represents a precompiled header (see "Precompiled // Headers" in GCC docs). bool is_precompiled_header(nonstd::string_view path); diff --git a/src/ccache.cpp b/src/ccache.cpp index e2ed2ea11..885e7fa7d 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -1726,8 +1726,7 @@ find_compiler(Context& ctx, const char* const* argv) std::string base(Util::base_name(argv[0])); if (Util::same_program_name(base, MYNAME)) { ctx.orig_args.pop_front(); - if (is_full_path(ctx.orig_args[0].c_str())) { - // A full path was given. + if (Util::is_full_path(ctx.orig_args[0])) { return; } base = std::string(Util::base_name(ctx.orig_args[0])); diff --git a/src/legacy_util.cpp b/src/legacy_util.cpp index ca79f26b3..09937a429 100644 --- a/src/legacy_util.cpp +++ b/src/legacy_util.cpp @@ -31,18 +31,6 @@ # include #endif -// Return whether the argument is a full path. -bool -is_full_path(const char* path) -{ -#ifdef _WIN32 - if (strchr(path, '\\')) { - return true; - } -#endif - return strchr(path, '/'); -} - // Update the modification time of a file in the cache to save it from LRU // cleanup. void diff --git a/src/legacy_util.hpp b/src/legacy_util.hpp index 44b018fe5..523e1621e 100644 --- a/src/legacy_util.hpp +++ b/src/legacy_util.hpp @@ -22,7 +22,6 @@ #include -bool is_full_path(const char* path); void update_mtime(const char* path); void x_exit(int status) ATTR_NORETURN; int x_rename(const char* oldpath, const char* newpath);