diff options
-rw-r--r-- | src/pseudotalloc/pseudotalloc.c | 16 | ||||
-rw-r--r-- | src/pseudotalloc/talloc.h | 2 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/pseudotalloc/pseudotalloc.c b/src/pseudotalloc/pseudotalloc.c index fe7f1edc..bc7a4910 100644 --- a/src/pseudotalloc/pseudotalloc.c +++ b/src/pseudotalloc/pseudotalloc.c @@ -5,6 +5,7 @@ #include "talloc.h" #include <string.h> +#include <stdio.h> void *_talloc_zero(const void *ctx, size_t size, const char *name) { @@ -61,3 +62,18 @@ void *_talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const { return talloc_zero_size(ctx, el_size * count); } + +char *talloc_asprintf(const void *ctx, const char *fmt, ...) +{ + char *buf; + size_t len = 128; + va_list args; + va_start(args, fmt); + + buf = talloc_size(ctx, len); + if (len < vsnprintf(buf, len, fmt, args)) + strcpy(&buf[len-6], "[...]"); + + va_end(args); + return buf; +} diff --git a/src/pseudotalloc/talloc.h b/src/pseudotalloc/talloc.h index c7127deb..f4c0a74f 100644 --- a/src/pseudotalloc/talloc.h +++ b/src/pseudotalloc/talloc.h @@ -39,4 +39,4 @@ void *_talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const char *name); - +char *talloc_asprintf(const void *ctx, const char *fmt, ...); |