From f22a76e9110e8e31efa3781b1a3cf2b4565d9e8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Mon, 28 Jul 2014 20:24:29 +0200 Subject: strbuf: add strbuf_getcwd() Add strbuf_getcwd(), which puts the current working directory into a strbuf. Because it doesn't use a fixed-size buffer it supports arbitrarily long paths, provided the platform's getcwd() does as well. At least on Linux and FreeBSD it handles paths longer than PATH_MAX just fine. Suggested-by: Karsten Blees Helped-by: Duy Nguyen Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- strbuf.h | 1 + 1 file changed, 1 insertion(+) (limited to 'strbuf.h') diff --git a/strbuf.h b/strbuf.h index 39c14cfa38..23b16c6cdf 100644 --- a/strbuf.h +++ b/strbuf.h @@ -163,6 +163,7 @@ extern size_t strbuf_fread(struct strbuf *, size_t, FILE *); extern ssize_t strbuf_read(struct strbuf *, int fd, size_t hint); extern int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint); extern int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint); +extern int strbuf_getcwd(struct strbuf *sb); extern int strbuf_getwholeline(struct strbuf *, FILE *, int); extern int strbuf_getline(struct strbuf *, FILE *, int); -- cgit v1.2.3 From 679eebe24d4c2120f8c01fb4524fcc489718fc9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Mon, 28 Jul 2014 20:33:55 +0200 Subject: abspath: convert absolute_path() to strbuf Move most of the code of absolute_path() into the new function strbuf_add_absolute_path() and in the process transform it to use struct strbuf and xgetcwd() instead of a PATH_MAX-sized buffer, which can be too small on some file systems. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- strbuf.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'strbuf.h') diff --git a/strbuf.h b/strbuf.h index 23b16c6cdf..455826ceb0 100644 --- a/strbuf.h +++ b/strbuf.h @@ -179,6 +179,8 @@ extern void strbuf_addstr_urlencode(struct strbuf *, const char *, int reserved); extern void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes); +extern void strbuf_add_absolute_path(struct strbuf *sb, const char *path); + __attribute__((format (printf,1,2))) extern int printf_ln(const char *fmt, ...); __attribute__((format (printf,2,3))) -- cgit v1.2.3