summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorJohannes Sixt <johannes.sixt@telecom.at>2008-07-21 21:19:57 +0200
committerJunio C Hamano <gitster@pobox.com>2008-07-25 17:41:13 -0700
commit35eeef47220c68c92d0f377f5678c42da2232c20 (patch)
treed778e47415f172e57daa700118336a925368a48a /compat
parentbf74a88244c4fe631535b50ef090541dddf9029d (diff)
downloadgit-35eeef47220c68c92d0f377f5678c42da2232c20.tar.gz
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>
Diffstat (limited to 'compat')
-rw-r--r--compat/mingw.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/compat/mingw.h b/compat/mingw.h
index 8ffec51e73..290a9e6f82 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -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)