summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compat/win32/path-utils.h11
-rw-r--r--git-compat-util.h8
-rw-r--r--run-command.c10
3 files changed, 24 insertions, 5 deletions
diff --git a/compat/win32/path-utils.h b/compat/win32/path-utils.h
index f2e70872cd..bba2b64408 100644
--- a/compat/win32/path-utils.h
+++ b/compat/win32/path-utils.h
@@ -20,6 +20,17 @@ static inline char *win32_find_last_dir_sep(const char *path)
return ret;
}
#define find_last_dir_sep win32_find_last_dir_sep
+static inline int win32_has_dir_sep(const char *path)
+{
+ /*
+ * See how long the non-separator part of the given path is, and
+ * if and only if it covers the whole path (i.e. path[len] is NUL),
+ * there is no separator in the path---otherwise there is a separator.
+ */
+ size_t len = strcspn(path, "/\\");
+ return !!path[len];
+}
+#define has_dir_sep(path) win32_has_dir_sep(path)
int win32_offset_1st_component(const char *path);
#define offset_1st_component win32_offset_1st_component
diff --git a/git-compat-util.h b/git-compat-util.h
index aed0b5d4f9..8ba576e81e 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -389,6 +389,14 @@ static inline char *git_find_last_dir_sep(const char *path)
#define find_last_dir_sep git_find_last_dir_sep
#endif
+#ifndef has_dir_sep
+static inline int git_has_dir_sep(const char *path)
+{
+ return !!strchr(path, '/');
+}
+#define has_dir_sep(path) git_has_dir_sep(path)
+#endif
+
#ifndef query_user_email
#define query_user_email() NULL
#endif
diff --git a/run-command.c b/run-command.c
index f5e1149f9b..0f41af3b55 100644
--- a/run-command.c
+++ b/run-command.c
@@ -421,12 +421,12 @@ static int prepare_cmd(struct argv_array *out, const struct child_process *cmd)
}
/*
- * If there are no '/' characters in the command then perform a path
- * lookup and use the resolved path as the command to exec. If there
- * are '/' characters, we have exec attempt to invoke the command
- * directly.
+ * If there are no dir separator characters in the command then perform
+ * a path lookup and use the resolved path as the command to exec. If
+ * there are dir separator characters, we have exec attempt to invoke
+ * the command directly.
*/
- if (!strchr(out->argv[1], '/')) {
+ if (!has_dir_sep(out->argv[1])) {
char *program = locate_in_PATH(out->argv[1]);
if (program) {
free((char *)out->argv[1]);