diff options
-rw-r--r-- | include/mupdf/fitz/output.h | 5 | ||||
-rw-r--r-- | source/fitz/printf.c | 16 |
2 files changed, 21 insertions, 0 deletions
diff --git a/include/mupdf/fitz/output.h b/include/mupdf/fitz/output.h index 48bcc502..9dd3de57 100644 --- a/include/mupdf/fitz/output.h +++ b/include/mupdf/fitz/output.h @@ -301,6 +301,11 @@ size_t fz_vsnprintf(char *buffer, size_t space, const char *fmt, va_list args); size_t fz_snprintf(char *buffer, size_t space, const char *fmt, ...); /* + fz_asprintf: Print to allocated string. +*/ +char *fz_asprintf(fz_context *ctx, const char *fmt, ...); + +/* fz_tempfilename: Get a temporary filename based upon 'base'. 'hint' is the path of a file (normally the existing document file) 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; +} |