From: Joel Rosdahl Date: Sat, 22 Feb 2020 12:46:30 +0000 (+0100) Subject: Use find_executable_in_path to find executable in hash_command_output X-Git-Tag: v4.0~605 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2494943e7f6e3401f8102b45d2023dac9213120f;p=thirdparty%2Fccache.git Use find_executable_in_path to find executable in hash_command_output This makes the Windows version behave similar to the non-Windows version: just search in $PATH, not potentially in the path specified by the “path” configuration setting. --- diff --git a/src/execute.cpp b/src/execute.cpp index ffbf53d31..8b4068870 100644 --- a/src/execute.cpp +++ b/src/execute.cpp @@ -28,10 +28,6 @@ using nonstd::string_view; -static char* find_executable_in_path(const char* name, - const char* exclude_name, - const char* path); - #ifdef _WIN32 int execute(char** argv, int fd_out, int fd_err, pid_t* /*pid*/) @@ -324,11 +320,15 @@ find_executable(const Context& ctx, const char* name, const char* exclude_name) return find_executable_in_path(name, exclude_name, path); } -static char* +char* find_executable_in_path(const char* name, const char* exclude_name, const char* path) { + if (!path) { + return nullptr; + } + char* path_buf = x_strdup(path); // Search the path looking for the first compiler of the right name that diff --git a/src/execute.hpp b/src/execute.hpp index 10702de5d..81794d7c1 100644 --- a/src/execute.hpp +++ b/src/execute.hpp @@ -25,5 +25,9 @@ struct Context; int execute(char** argv, int fd_out, int fd_err, pid_t* pid); char* find_executable(const Context& ctx, const char* name, const char* exclude_name); +char* find_executable_in_path(const char* name, + const char* exclude_name, + const char* path); + void print_command(FILE* fp, char** argv); char* format_command(const char* const* argv); diff --git a/src/hashutil.cpp b/src/hashutil.cpp index ce3927354..3e680dfa4 100644 --- a/src/hashutil.cpp +++ b/src/hashutil.cpp @@ -325,7 +325,7 @@ hash_command_output(Context& ctx, STARTUPINFO si; memset(&si, 0x00, sizeof(si)); - char* path = find_executable(ctx, args->argv[0], nullptr); + char* path = find_executable_in_path(args->argv[0], nullptr, getenv("PATH")); if (!path) { path = args->argv[0]; }