From 15f43c4cccc960559ea6967c7fe1439cde54b0aa Mon Sep 17 00:00:00 2001 From: Paul Gardiner Date: Thu, 31 May 2012 16:38:54 +0100 Subject: A few general utility functions added for the sake of the forms work --- fitz/fitz-internal.h | 7 +++++++ fitz/fitz.h | 2 +- fitz/stm_buffer.c | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) (limited to 'fitz') diff --git a/fitz/fitz-internal.h b/fitz/fitz-internal.h index 05d7b52f..2f7f8041 100644 --- a/fitz/fitz-internal.h +++ b/fitz/fitz-internal.h @@ -419,6 +419,13 @@ void fz_write_buffer_bits(fz_context *ctx, fz_buffer *buf, int val, int bits); void fz_write_buffer_pad(fz_context *ctx, fz_buffer *buf); +/* + fz_buffer_printf: print formatted to a buffer. The buffer will + grow, but the caller must ensure that no more than 256 bytes are + added to the buffer per call. +*/ +void fz_buffer_printf(fz_context *ctx, fz_buffer *buffer, char *fmt, ...); + struct fz_stream_s { fz_context *ctx; diff --git a/fitz/fitz.h b/fitz/fitz.h index ee00b2ed..a66976af 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -403,7 +403,7 @@ void *fz_calloc(fz_context *ctx, unsigned int count, unsigned int size); exception on failure to allocate. */ #define fz_malloc_struct(CTX, STRUCT) \ - Memento_label(fz_calloc(CTX,1,sizeof(STRUCT)), #STRUCT) + ((STRUCT *)Memento_label(fz_calloc(CTX,1,sizeof(STRUCT)), #STRUCT)) /* fz_malloc_array: Allocate a block of (non zeroed) memory (with diff --git a/fitz/stm_buffer.c b/fitz/stm_buffer.c index 58539bf8..d14b738f 100644 --- a/fitz/stm_buffer.c +++ b/fitz/stm_buffer.c @@ -159,3 +159,18 @@ void fz_write_buffer_pad(fz_context *ctx, fz_buffer *buf) { buf->unused_bits = 0; } + +void +fz_buffer_printf(fz_context *ctx, fz_buffer *buffer, char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + + /* Caller guarantees not to generate more than 256 bytes per call */ + while(buffer->cap - buffer->len < 256) + fz_grow_buffer(ctx, buffer); + + buffer->len += vsprintf(buffer->data + buffer->len, fmt, args); + + va_end(args); +} -- cgit v1.2.3