From: René Scharfe Date: Mon, 28 Jul 2014 18:27:34 +0000 (+0200) Subject: abspath: use strbuf_getcwd() to remember original working directory X-Git-Tag: v2.2.0-rc0~173^2~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=251277acdf8c8dee59bdd0e9e7b7e3502226cf9d;p=thirdparty%2Fgit.git abspath: use strbuf_getcwd() to remember original working directory Store the original working directory in a strbuf instead of in a fixed-sized buffer, in order to be able to handle longer paths. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- diff --git a/abspath.c b/abspath.c index ca33558a91..911e931cc0 100644 --- a/abspath.c +++ b/abspath.c @@ -41,7 +41,7 @@ static const char *real_path_internal(const char *path, int die_on_error) * here so that we can chdir() back to it at the end of the * function: */ - char cwd[1024] = ""; + struct strbuf cwd = STRBUF_INIT; int buf_index = 1; @@ -80,7 +80,7 @@ static const char *real_path_internal(const char *path, int die_on_error) } if (*buf) { - if (!*cwd && !getcwd(cwd, sizeof(cwd))) { + if (!cwd.len && strbuf_getcwd(&cwd)) { if (die_on_error) die_errno("Could not get current working directory"); else @@ -142,8 +142,9 @@ static const char *real_path_internal(const char *path, int die_on_error) retval = buf; error_out: free(last_elem); - if (*cwd && chdir(cwd)) - die_errno("Could not change back to '%s'", cwd); + if (cwd.len && chdir(cwd.buf)) + die_errno("Could not change back to '%s'", cwd.buf); + strbuf_release(&cwd); return retval; }