@matheusbsbs / matheus-bagliano / commits / 6fad004a37
Fork 0

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>

Johannes Sixt committed Apr 11, 2007 at 16:02 UTC 6fad004a37432e4378b6cce53eebe8a079104e93
1 file changed +29
exec_cmd.c
+29
@@ -8,7 +8,36 @@ static const char *argv_exec_path;
8
9 static const char *builtin_exec_path(void)
10 {
11 +#ifndef __MINGW32__
12 return GIT_EXEC_PATH;
13 +#else
14 + int len;
15 + char *p, *q, *sl;
16 + static char *ep;
17 + if (ep)
18 + return ep;
19 +
20 + len = strlen(_pgmptr);
21 + if (len < 2)
22 + return ep = ".";
23 +
24 + p = ep = xmalloc(len+1);
25 + q = _pgmptr;
26 + sl = NULL;
27 + /* copy program name, turn '\\' into '/', skip last part */
28 + while ((*p = *q)) {
29 + if (*q == '\\' || *q == '/') {
30 + *p = '/';
31 + sl = p;
32 + }
33 + p++, q++;
34 + }
35 + if (sl)
36 + *sl = '\0';
37 + else
38 + ep[0] = '.', ep[1] = '\0';
39 + return ep;
40 +#endif
41 }
42
43 void git_set_argv_exec_path(const char *exec_path)