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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Nguyán ThÃi Ngác Duy <pclouds@xxxxxxxxx>
---
  On Fri, Mar 18, 2011 at 5:34 PM, Nguyen Thai Ngoc Duy <pclouds@xxxxxxxxx> 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/AANLkTikXvx7-Q8B_dqG5mMHGK_Rw-dFaeQdXi0zW98SD@xxxxxxxxxxxxxx
  
  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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]