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>
Alex Riesen committed
Oct 26, 2008 at 22:59 UTC
108bebeab31881654b7b0f1b5b393a6655d74d3f
2 files changed
+18
cache.h
+3
@@ -480,6 +480,9 @@ extern int check_repository_format(void);
480
#define DATA_CHANGED 0x0020
481
#define TYPE_CHANGED 0x0040
482
483
+extern char *mksnpath(char *buf, size_t n, const char *fmt, ...)
484
+ __attribute__((format (printf, 3, 4)));
485
+
486
/* Return a statically allocated filename matching the sha1 signature */
487
extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
488
extern char *git_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
path.c
+15
@@ -32,6 +32,21 @@ static char *cleanup_path(char *path)
32
return path;
33
}
34
35
+char *mksnpath(char *buf, size_t n, const char *fmt, ...)
36
+{
37
+ va_list args;
38
+ unsigned len;
39
+
40
+ va_start(args, fmt);
41
+ len = vsnprintf(buf, n, fmt, args);
42
+ va_end(args);
43
+ if (len >= n) {
44
+ snprintf(buf, n, bad_path);
45
+ return buf;
46
+ }
47
+ return cleanup_path(buf);
48
+}
49
+
50
char *mkpath(const char *fmt, ...)
51
{
52
va_list args;