diff options
author | Alex Riesen <raa.lkml@gmail.com> | 2008-10-26 22:59:13 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-10-26 22:08:58 -0700 |
commit | 108bebeab31881654b7b0f1b5b393a6655d74d3f (patch) | |
tree | 49568beafbd6e9d84bcd200f6070b45b6ea74c8e /path.c | |
parent | 9fe7a643fcc56ca1c17afec5d5f8adca10cabdd1 (diff) | |
download | git-108bebeab31881654b7b0f1b5b393a6655d74d3f.tar.gz |
Add mksnpath which allows you to specify the output buffer
This is just vsnprintf's but additionally calls cleanup_path() on the
result. To be used as alternatives to mkpath() where the buffer for the
created path may not be reused by subsequent calls of the same formatting
function.
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'path.c')
-rw-r--r-- | path.c | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -32,6 +32,21 @@ static char *cleanup_path(char *path) return path; } +char *mksnpath(char *buf, size_t n, const char *fmt, ...) +{ + va_list args; + unsigned len; + + va_start(args, fmt); + len = vsnprintf(buf, n, fmt, args); + va_end(args); + if (len >= n) { + snprintf(buf, n, bad_path); + return buf; + } + return cleanup_path(buf); +} + char *mkpath(const char *fmt, ...) { va_list args; |