Re: [PATCH 2/6] Refactor git_set_argv0_path() to git_extract_argv0_path()
- From
Johannes Sixt <j6t@kdbg.org>
- Date
- Jan 13, 2009, 19:37 UTC
- Message-ID
- <200901132037.35096.j6t@kdbg.org>
- In-Reply-To
- <1231595452-27698-2-git-send-email-prohaska@zib.de>
On Samstag, 10. Januar 2009, Steffen Prohaska wrote:
Show 8 quoted lines
> @@ -63,9 +63,19 @@ const char *system_path(const char *path)
> return path;
> }
>
> -void git_set_argv0_path(const char *path)
> +const char *git_extract_argv0_path(const char *argv0)
> {
> - argv0_path = path;Please insert the 'if (argv0 && *argv0)' here to simplify the call sites. Or you could introduce this check later in 4/6 because the call site in this patch (main() of git.c) is simpler if it keeps the check.
Show 12 quoted lines
> + const char *slash = argv0 + strlen(argv0);
> +
> + while (argv0 <= slash && !is_dir_sep(*slash))
> + slash--;
> +
> + if (slash >= argv0) {
> + argv0_path = xstrndup(argv0, slash - argv0);
> + return slash + 1;
> + }
> +
> + return argv0;
> }-- Hannes