Subject: [PATCH 2/2] setup_gently: use xgetcwd()

From: Nguyễn Thái Ngọc Duy <[email-masked]>
Date: Fri, 18 Mar 2011 18:39:29 +0700

Signed-off-by: Nguyễn Thái Ngọc Duy <[email-masked]>
---
  On Fri, Mar 18, 2011 at 5:34 PM, Nguyen Thai Ngoc Duy <[email-masked]> wrote:
  > It was pointed out elsewhere [1] that PATH_MAX only specifies max
  > length of a path element, not full path. I think we'd need to stay
  > away from preallocated PATH_MAX-sized arrays.
  >
  > [1] http://mid.gmane.org/[email-masked]
  
  Perhaps this as a start? I don't intend to kill all PATH_MAX by myself
  though until I finish all other topics I'm working on.

 setup.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/setup.c b/setup.c
index 03cd84f..f7b3556 100644
--- a/setup.c
+++ b/setup.c
@@ -506,7 +506,8 @@ static dev_t get_device_or_die(const char *path, const char *prefix)
 static const char *setup_git_directory_gently_1(int *nongit_ok)
 {
 	const char *env_ceiling_dirs = getenv(CEILING_DIRECTORIES_ENVIRONMENT);
-	static char cwd[PATH_MAX+1];
+	static struct strbuf sb_cwd = STRBUF_INIT;
+	char *cwd;
 	const char *gitdirenv, *ret;
 	char *gitfile;
 	int len, offset, ceil_offset;
@@ -521,9 +522,9 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)
 	if (nongit_ok)
 		*nongit_ok = 0;
 
-	if (!getcwd(cwd, sizeof(cwd)-1))
-		die_errno("Unable to read current working directory");
-	offset = len = strlen(cwd);
+	xgetcwd(&sb_cwd);
+	offset = len = sb_cwd.len;
+	cwd = sb_cwd.buf;
 
 	/*
 	 * If GIT_DIR is set explicitly, we're not going
-- 
1.7.4.74.g639db