Skip to content

Commit

Permalink
Windows: Make sure argv[0] has a path
Browse files Browse the repository at this point in the history
Since the exec-path on Windows is derived from the program invocation path,
we must ensure that argv[0] always has a path. Unfortunately, if a program
is invoked from CMD, argv[0] has no path. But on the other hand, the
C runtime offers a global variable, _pgmptr, that always has the full path
to the program. We hook into main() with a preprocessor macro, where we
replace argv[0].

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Johannes Sixt authored and Junio C Hamano committed Jul 26, 2008
1 parent bf74a88 commit 35eeef4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions compat/mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,15 @@ void mingw_open_html(const char *path);
char **copy_environ(void);
void free_environ(char **env);
char **env_setenv(char **env, const char *name);

/*
* A replacement of main() that ensures that argv[0] has a path
*/

#define main(c,v) main(int argc, const char **argv) \
{ \
static int mingw_main(); \
argv[0] = xstrdup(_pgmptr); \
return mingw_main(argc, argv); \
} \
static int mingw_main(c,v)

0 comments on commit 35eeef4

Please sign in to comment.