diff options
Diffstat (limited to 'fitz')
-rw-r--r-- | fitz/fitz-internal.h | 7 | ||||
-rw-r--r-- | fitz/fitz.h | 2 | ||||
-rw-r--r-- | fitz/stm_buffer.c | 15 |
3 files changed, 23 insertions, 1 deletions
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); +} |