]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Use find_executable_in_path to find executable in hash_command_output
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 22 Feb 2020 12:46:30 +0000 (13:46 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 22 Feb 2020 20:53:27 +0000 (21:53 +0100)
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.

src/execute.cpp
src/execute.hpp
src/hashutil.cpp

index ffbf53d313f349d8807451896d2c0cfdd78605e3..8b40688705f5970c0d57ed9bc1c34271a6c43981 100644 (file)
 
 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
index 10702de5da0bc0045ccb2695a03abdda4f52a9df..81794d7c1c70251e546b35ea91fc35e1561813b7 100644 (file)
@@ -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);
index ce39273540e73f22d5605c9ae9b20a06696fdbc7..3e680dfa4185b00aff19dc54315768e99b7bf582 100644 (file)
@@ -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];
   }