summaryrefslogtreecommitdiff
path: root/path.c
diff options
context:
space:
mode:
authorLibravatar Alex Riesen <raa.lkml@gmail.com>2008-10-27 11:17:51 +0100
committerLibravatar Junio C Hamano <gitster@pobox.com>2008-10-30 17:30:55 -0700
commitaba13e7c0566f578f866504bfcb388a72f7e5079 (patch)
tree6c34533e3c73d7d8034c0934603ceef03f6fd157 /path.c
parentFix potentially dangerous use of git_path in ref.c (diff)
downloadtgif-aba13e7c0566f578f866504bfcb388a72f7e5079.tar.xz
git_pathdup: returns xstrdup-ed copy of the formatted path
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'path.c')
-rw-r--r--path.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/path.c b/path.c
index 85ab28a0f1..092ce57190 100644
--- a/path.c
+++ b/path.c
@@ -47,10 +47,9 @@ char *mksnpath(char *buf, size_t n, const char *fmt, ...)
return cleanup_path(buf);
}
-char *git_snpath(char *buf, size_t n, const char *fmt, ...)
+static char *git_vsnpath(char *buf, size_t n, const char *fmt, va_list args)
{
const char *git_dir = get_git_dir();
- va_list args;
size_t len;
len = strlen(git_dir);
@@ -59,9 +58,7 @@ char *git_snpath(char *buf, size_t n, const char *fmt, ...)
memcpy(buf, git_dir, len);
if (len && !is_dir_sep(git_dir[len-1]))
buf[len++] = '/';
- va_start(args, fmt);
len += vsnprintf(buf + len, n - len, fmt, args);
- va_end(args);
if (len >= n)
goto bad;
return cleanup_path(buf);
@@ -70,6 +67,25 @@ bad:
return buf;
}
+char *git_snpath(char *buf, size_t n, const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ (void)git_vsnpath(buf, n, fmt, args);
+ va_end(args);
+ return buf;
+}
+
+char *git_pathdup(const char *fmt, ...)
+{
+ char path[PATH_MAX];
+ va_list args;
+ va_start(args, fmt);
+ (void)git_vsnpath(path, sizeof(path), fmt, args);
+ va_end(args);
+ return xstrdup(path);
+}
+
char *mkpath(const char *fmt, ...)
{
va_list args;