use xgetcwd() to get the current directory or die

Convert several calls of getcwd() and die() to use xgetcwd() instead.
This way we get rid of fixed-size buffers (which can be too small
depending on the used file system) and gain consistent error messages.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
René Scharfe
2014-07-28 20:30:39 +02:00
committed by Junio C Hamano
parent aa14e980ff
commit 56b9f6e738
5 changed files with 26 additions and 22 deletions

View File

@ -734,7 +734,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
}
if (!strcmp(arg, "--git-dir")) {
const char *gitdir = getenv(GIT_DIR_ENVIRONMENT);
static char cwd[PATH_MAX];
char *cwd;
int len;
if (gitdir) {
puts(gitdir);
@ -744,10 +744,10 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
puts(".git");
continue;
}
if (!getcwd(cwd, PATH_MAX))
die_errno("unable to get current working directory");
cwd = xgetcwd();
len = strlen(cwd);
printf("%s%s.git\n", cwd, len && cwd[len-1] != '/' ? "/" : "");
free(cwd);
continue;
}
if (!strcmp(arg, "--resolve-git-dir")) {