From c1be1cb7ea064bae5ee1cd226aa42b767f2b52c4 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 10 Apr 2018 11:05:45 -0400 Subject: exec_cmd: provide a new-style RUNTIME_PREFIX helper for Windows The RUNTIME_PREFIX feature comes from Git for Windows, but it was enhanced to allow support for other platforms. While changing the original idea, the concept was also improved by not forcing argv[0] to be adjusted. Let's allow the same for Windows by implementing a helper just as for the other platforms. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- exec_cmd.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'exec_cmd.c') diff --git a/exec_cmd.c b/exec_cmd.c index 38d52d90a2..6e114f8b3a 100644 --- a/exec_cmd.c +++ b/exec_cmd.c @@ -144,6 +144,24 @@ static int git_get_exec_path_darwin(struct strbuf *buf) } #endif /* HAVE_NS_GET_EXECUTABLE_PATH */ +#ifdef HAVE_WPGMPTR +/* + * Resolves the executable path by using the global variable _wpgmptr. + * + * Returns 0 on success, -1 on failure. + */ +static int git_get_exec_path_wpgmptr(struct strbuf *buf) +{ + int len = wcslen(_wpgmptr) * 3 + 1; + strbuf_grow(buf, len); + len = xwcstoutf(buf->buf, _wpgmptr, len); + if (len < 0) + return -1; + buf->len += len; + return 0; +} +#endif /* HAVE_WPGMPTR */ + /* * Resolves the absolute path of the current executable. * @@ -178,6 +196,10 @@ static int git_get_exec_path(struct strbuf *buf, const char *argv0) git_get_exec_path_procfs(buf) && #endif /* PROCFS_EXECUTABLE_PATH */ +#ifdef HAVE_WPGMPTR + git_get_exec_path_wpgmptr(buf) && +#endif /* HAVE_WPGMPTR */ + git_get_exec_path_from_argv0(buf, argv0)) { return -1; } -- cgit v1.2.3