@matheusbsbs / matheus-bagliano / commits / 35eeef4722
Fork 0

Windows: Make sure argv[0] has a path

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>

Johannes Sixt committed Jul 21, 2008 at 21:19 UTC 35eeef47220c68c92d0f377f5678c42da2232c20
1 file changed +12
compat/mingw.h
+12
@@ -223,3 +223,15 @@ void mingw_open_html(const char *path);
223 char **copy_environ(void);
224 void free_environ(char **env);
225 char **env_setenv(char **env, const char *name);
226 +
227 +/*
228 + * A replacement of main() that ensures that argv[0] has a path
229 + */
230 +
231 +#define main(c,v) main(int argc, const char **argv) \
232 +{ \
233 + static int mingw_main(); \
234 + argv[0] = xstrdup(_pgmptr); \
235 + return mingw_main(argc, argv); \
236 +} \
237 +static int mingw_main(c,v)