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

[PATCH v2 3/4] wrapper: add xgetcwd()

From
René Scharfe <l.s.r@web.de>
Date
Jul 20, 2014, 16:50 UTC
Message-ID
<53CBF359.2040400@web.de>
In-Reply-To
<53CBF277.3090101@web.de>

Add the helper function xgetcwd(), which returns the current directory or dies. The returned string has to be free()d after use.

Helped-by: Duy Nguyen <pclouds@gmail.com>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 git-compat-util.h | 1 +
 wrapper.c         | 8 ++++++++
 2 files changed, 9 insertions(+)
diff --git a/git-compat-util.h b/git-compat-util.h
index 0b53c9a..d64d012 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -605,6 +605,7 @@ extern int xmkstemp(char *template);
 extern int xmkstemp_mode(char *template, int mode);
 extern int odb_mkstemp(char *template, size_t limit, const char *pattern);
 extern int odb_pack_keep(char *name, size_t namesz, const unsigned char *sha1);
+extern char *xgetcwd(void);
 
 static inline size_t xsize_t(off_t len)
 {
diff --git a/wrapper.c b/wrapper.c
index bc1bfb8..bd24cda 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -493,3 +493,11 @@ struct passwd *xgetpwuid_self(void)
 		    errno ? strerror(errno) : _("no such user"));
 	return pw;
 }
+
+char *xgetcwd(void)
+{
+	struct strbuf sb = STRBUF_INIT;
+	if (strbuf_getcwd(&sb))
+		die_errno(_("unable to get current working directory"));
+	return strbuf_detach(&sb, NULL);
+}
-- 
2.0.2
Previous: Junio C HamanoNext: René Scharfe
Message 8 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.