summaryrefslogtreecommitdiff
path: root/source/fitz/output.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2017-03-15 16:27:15 +0100
committerTor Andersson <tor.andersson@artifex.com>2017-03-22 12:07:26 +0100
commite013fd7d0f5ae8f5c994aad4d02f5169946f1a26 (patch)
treebe8a7c8006b1e22a04d70c8db9bb95120b1c7f3a /source/fitz/output.c
parent8e791ab5cd73dc783aded93f2dd7c77d89623fe8 (diff)
downloadmupdf-e013fd7d0f5ae8f5c994aad4d02f5169946f1a26.tar.xz
Simplify string formatter API.
Emit characters with callbacks so we don't need to do two passes using vsnprintf to count, format, and copy the result.
Diffstat (limited to 'source/fitz/output.c')
-rw-r--r--source/fitz/output.c37
1 files changed, 9 insertions, 28 deletions
diff --git a/source/fitz/output.c b/source/fitz/output.c
index bd4dba66..961bafe5 100644
--- a/source/fitz/output.c
+++ b/source/fitz/output.c
@@ -266,36 +266,17 @@ fz_tell_output(fz_context *ctx, fz_output *out)
return out->tell(ctx, out->state);
}
-void
-fz_write_vprintf(fz_context *ctx, fz_output *out, const char *fmt, va_list old_args)
+static void
+fz_write_emit(fz_context *ctx, void *out, int c)
{
- char buffer[256], *p = buffer;
- size_t len;
- va_list args;
+ fz_write_byte(ctx, out, c);
+}
+void
+fz_write_vprintf(fz_context *ctx, fz_output *out, const char *fmt, va_list args)
+{
if (!out) return;
-
- /* First try using our fixed size buffer */
- va_copy(args, old_args);
- len = fz_vsnprintf(buffer, sizeof buffer, fmt, args);
- va_copy_end(args);
-
- /* If that failed, allocate a big enough buffer */
- if (len > sizeof buffer)
- {
- p = fz_malloc(ctx, len);
- va_copy(args, old_args);
- fz_vsnprintf(p, len, fmt, args);
- va_copy_end(args);
- }
-
- fz_try(ctx)
- out->write(ctx, out->state, p, len);
- fz_always(ctx)
- if (p != buffer)
- fz_free(ctx, p);
- fz_catch(ctx)
- fz_rethrow(ctx);
+ fz_format_string(ctx, out, fz_write_emit, fmt, args);
}
void
@@ -304,7 +285,7 @@ fz_write_printf(fz_context *ctx, fz_output *out, const char *fmt, ...)
va_list args;
if (!out) return;
va_start(args, fmt);
- fz_write_vprintf(ctx, out, fmt, args);
+ fz_format_string(ctx, out, fz_write_emit, fmt, args);
va_end(args);
}