diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2017-03-16 14:26:53 +0100 |
---|---|---|
committer | Sebastian Rasmussen <sebras@gmail.com> | 2017-04-11 17:48:01 +0800 |
commit | 5232ccddf461882a69a0e122a635387f8fc6980e (patch) | |
tree | 06d60d207ad9a5a09b903249370a3e9f3e1e1b94 /source/fitz | |
parent | e089b2e2c1d38c5696c7dfd741e21f8f3ef22b14 (diff) | |
download | mupdf-5232ccddf461882a69a0e122a635387f8fc6980e.tar.xz |
Add fz_asprintf function to allocate a string and format output.
Diffstat (limited to 'source/fitz')
-rw-r--r-- | source/fitz/printf.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/source/fitz/printf.c b/source/fitz/printf.c index cea13cc1..ddb8f17c 100644 --- a/source/fitz/printf.c +++ b/source/fitz/printf.c @@ -462,3 +462,19 @@ fz_snprintf(char *buffer, size_t space, const char *fmt, ...) return out.n - 1; } + +char * +fz_asprintf(fz_context *ctx, const char *fmt, ...) +{ + int len; + char *mem; + va_list ap; + va_start(ap, fmt); + len = fz_vsnprintf(NULL, 0, fmt, ap); + va_end(ap); + mem = fz_malloc(ctx, len+1); + va_start(ap, fmt); + fz_vsnprintf(mem, len+1, fmt, ap); + va_end(ap); + return mem; +} |