Skip to content

Commit

Permalink
Windows: Compute the fallback for exec_path from the program invocation.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Johannes Sixt committed Jun 26, 2008
1 parent 4ec22a4 commit 6fad004
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions exec_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6fad004

Please sign in to comment.