git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/4] use strbuf_getcwd() to get the current working directory without fixed-sized buffers

From
René Scharfe <l.s.r@web.de>
Date
Jul 20, 2014, 16:49 UTC
Message-ID
<53CBF332.2050301@web.de>
In-Reply-To
<53CBF277.3090101@web.de>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 builtin/init-db.c | 8 ++++----
 git.c             | 6 ++++--
 2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 56f85e2..c4958b6 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -535,10 +535,10 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
 		usage(init_db_usage[0]);
 	}
 	if (is_bare_repository_cfg == 1) {
-		static char git_dir[PATH_MAX+1];
-
-		setenv(GIT_DIR_ENVIRONMENT,
-			getcwd(git_dir, sizeof(git_dir)), argc > 0);
+		struct strbuf cwd = STRBUF_INIT;
+		strbuf_getcwd(&cwd);
+		setenv(GIT_DIR_ENVIRONMENT, cwd.buf, argc > 0);
+		strbuf_release(&cwd);
 	}
 
 	if (init_shared_repository != -1)
diff --git a/git.c b/git.c
index 5b6c761..3f52c43 100644
--- a/git.c
+++ b/git.c
@@ -161,9 +161,11 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 			if (envchanged)
 				*envchanged = 1;
 		} else if (!strcmp(cmd, "--bare")) {
-			static char git_dir[PATH_MAX+1];
+			struct strbuf cwd = STRBUF_INIT;
 			is_bare_repository_cfg = 1;
-			setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir, sizeof(git_dir)), 0);
+			strbuf_getcwd(&cwd);
+			setenv(GIT_DIR_ENVIRONMENT, cwd.buf, 0);
+			strbuf_release(&cwd);
 			setenv(GIT_IMPLICIT_WORK_TREE_ENVIRONMENT, "0", 1);
 			if (envchanged)
 				*envchanged = 1;
-- 
2.0.2
Previous: René ScharfeNext: Jeff King
Message 3 of 9 in “getcwd without PATH_MAX”
  1. 0/4 getcwd without PATH_MAXRené Scharfe, Jul 20, 2014
  2. 1/4 strbuf: add strbuf_getcwd()René Scharfe, Jul 20, 2014
  3. 2/4 use strbuf_getcwd() to get the current working directory without fixed-sized buffersRené Scharfe, Jul 20, 2014
  4. Jeff KingJul 21, 2014
  5. René ScharfeJul 21, 2014
  6. Jeff KingJul 22, 2014
  7. Junio C HamanoJul 21, 2014
  8. 3/4 wrapper: add xgetcwd()René Scharfe, Jul 20, 2014
  9. 4/4 use xgetcwd() get the current directory or dieRené Scharfe, Jul 20, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.