summaryrefslogtreecommitdiff
path: root/fitz
diff options
context:
space:
mode:
authorPaul Gardiner <paul@glidos.net>2012-05-31 16:38:54 +0100
committerRobin Watts <robin.watts@artifex.com>2012-06-12 16:55:29 +0100
commit15f43c4cccc960559ea6967c7fe1439cde54b0aa (patch)
tree0a9385cb96ef1e37d7fed5b158739494bf367bb6 /fitz
parent2dfb38a5d55737e0bfaca9af5f77f17b3bde8f41 (diff)
downloadmupdf-15f43c4cccc960559ea6967c7fe1439cde54b0aa.tar.xz
A few general utility functions added for the sake of the forms work
Diffstat (limited to 'fitz')
-rw-r--r--fitz/fitz-internal.h7
-rw-r--r--fitz/fitz.h2
-rw-r--r--fitz/stm_buffer.c15
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);
+}