]> git.ipfire.org Git - thirdparty/git.git/commitdiff
run-command: make `exists_in_PATH()` non-static
authorPranit Bauva <pranit.bauva@gmail.com>
Mon, 13 Sep 2021 17:39:01 +0000 (19:39 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Sep 2021 20:37:37 +0000 (13:37 -0700)
Remove the `static` keyword from `exists_in_PATH()` function
and declare the function in `run-command.h` file.
The function will be used in bisect_visualize() in a later
commit.

Mentored by: Christian Couder <chriscool@tuxfamily.org>
Mentored by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Tanushree Tumane <tanushreetumane@gmail.com>
Signed-off-by: Miriam Rubio <mirucam@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
run-command.c
run-command.h

index f72e72cce73f1a1decbdd99b098f050f37bea41f..da02553f4423184611dba74a3af0e1be3b2d1dd4 100644 (file)
@@ -210,9 +210,9 @@ static char *locate_in_PATH(const char *file)
        return NULL;
 }
 
-static int exists_in_PATH(const char *file)
+int exists_in_PATH(const char *command)
 {
-       char *r = locate_in_PATH(file);
+       char *r = locate_in_PATH(command);
        int found = r != NULL;
        free(r);
        return found;
index af1296769f986242cffe3dd9ac806e4dfffca507..aad027984d1b1c29a3c5d4852c770e33b1bf2da5 100644 (file)
@@ -182,6 +182,18 @@ void child_process_clear(struct child_process *);
 
 int is_executable(const char *name);
 
+/**
+ * Check if the command exists on $PATH. This emulates the path search that
+ * execvp would perform, without actually executing the command so it
+ * can be used before fork() to prepare to run a command using
+ * execve() or after execvp() to diagnose why it failed.
+ *
+ * The caller should ensure that command contains no directory separators.
+ *
+ * Returns 1 if it is found in $PATH or 0 if the command could not be found.
+ */
+int exists_in_PATH(const char *command);
+
 /**
  * Start a sub-process. Takes a pointer to a `struct child_process`
  * that specifies the details and returns pipe FDs (if requested).