summaryrefslogtreecommitdiff
path: root/exec_cmd.c
diff options
context:
space:
mode:
authorJohannes Sixt <johannes.sixt@telecom.at>2007-04-11 16:02:45 +0200
committerJohannes Sixt <johannes.sixt@telecom.at>2008-06-26 08:45:12 +0200
commit6fad004a37432e4378b6cce53eebe8a079104e93 (patch)
treecd437e6cd47a75e5596d9950c342c739fa9961d6 /exec_cmd.c
parent4ec22a48c0575c8a303cd00b5ef4b3d703fbf8b3 (diff)
downloadgit-6fad004a37432e4378b6cce53eebe8a079104e93.tar.gz
Windows: Compute the fallback for exec_path from the program invocation.
Since on Windows the user is fairly free where to install programs, we cannot rely on a hard-coded path. We use the program name to derive the installation directory and use that as exec_path. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
Diffstat (limited to 'exec_cmd.c')
-rw-r--r--exec_cmd.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/exec_cmd.c b/exec_cmd.c
index 6618aad7ab..84db7ee664 100644
--- a/exec_cmd.c
+++ b/exec_cmd.c
@@ -8,7 +8,36 @@ static const char *argv_exec_path;
static const char *builtin_exec_path(void)
{
+#ifndef __MINGW32__
return GIT_EXEC_PATH;
+#else
+ int len;
+ char *p, *q, *sl;
+ static char *ep;
+ if (ep)
+ return ep;
+
+ len = strlen(_pgmptr);
+ if (len < 2)
+ return ep = ".";
+
+ p = ep = xmalloc(len+1);
+ q = _pgmptr;
+ sl = NULL;
+ /* copy program name, turn '\\' into '/', skip last part */
+ while ((*p = *q)) {
+ if (*q == '\\' || *q == '/') {
+ *p = '/';
+ sl = p;
+ }
+ p++, q++;
+ }
+ if (sl)
+ *sl = '\0';
+ else
+ ep[0] = '.', ep[1] = '\0';
+ return ep;
+#endif
}
void git_set_argv_exec_path(const char *exec_path)