summaryrefslogtreecommitdiff
path: root/path.c
diff options
context:
space:
mode:
authorAlex Riesen <raa.lkml@gmail.com>2008-10-27 10:22:21 +0100
committerJunio C Hamano <gitster@pobox.com>2008-10-30 17:00:14 -0700
commitfe2d7776d5191896e361973f478ca078fa95b324 (patch)
treed7aefac116a2a575831e7515612223a3b20e0bea /path.c
parent9fa03c177ff826b439537072338af958fe01c257 (diff)
downloadgit-fe2d7776d5191896e361973f478ca078fa95b324.tar.gz
Add git_snpath: a .git path formatting routine with output buffer
The function's purpose is to replace git_path where the buffer of formatted path may not be reused by subsequent calls of the function or will be copied anyway. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'path.c')
-rw-r--r--path.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/path.c b/path.c
index 8b64878c21..85ab28a0f1 100644
--- a/path.c
+++ b/path.c
@@ -47,6 +47,29 @@ 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, ...)
+{
+ const char *git_dir = get_git_dir();
+ va_list args;
+ size_t len;
+
+ len = strlen(git_dir);
+ if (n < len + 1)
+ goto bad;
+ 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);
+bad:
+ snprintf(buf, n, bad_path);
+ return buf;
+}
+
char *mkpath(const char *fmt, ...)
{
va_list args;