wrapper: add xgetcwd()

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jul 28, 2014 at 20:29 UTC aa14e980fff55e090dd42174ab4f37fe4b3dfa1e
2 files changed +9
git-compat-util.h
+1
@@ -538,6 +538,7 @@ extern int xmkstemp(char *template);
538 extern int xmkstemp_mode(char *template, int mode);
539 extern int odb_mkstemp(char *template, size_t limit, const char *pattern);
540 extern int odb_pack_keep(char *name, size_t namesz, const unsigned char *sha1);
541 +extern char *xgetcwd(void);
542
543 static inline size_t xsize_t(off_t len)
544 {
wrapper.c
+8
@@ -493,3 +493,11 @@ struct passwd *xgetpwuid_self(void)
493 errno ? strerror(errno) : _("no such user"));
494 return pw;
495 }
496 +
497 +char *xgetcwd(void)
498 +{
499 + struct strbuf sb = STRBUF_INIT;
500 + if (strbuf_getcwd(&sb))
501 + die_errno(_("unable to get current working directory"));
502 + return strbuf_detach(&sb, NULL);
503 +}