From 37f95f87bdfb2e0b01d649afae5fffe60bf99d3a Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Fri, 11 Nov 2016 16:05:30 +0000 Subject: Make fz_buffer structure private to fitz. Move the definition of the structure contents into new fitz-imp.h file. Make all code outside of fitz access the buffer through the defined API. Add a convenience API for people that want to get buffers as null terminated C strings. --- include/mupdf/fitz/buffer.h | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/mupdf/fitz/buffer.h b/include/mupdf/fitz/buffer.h index 40e46e73..70214b21 100644 --- a/include/mupdf/fitz/buffer.h +++ b/include/mupdf/fitz/buffer.h @@ -38,14 +38,13 @@ void fz_drop_buffer(fz_context *ctx, fz_buffer *buf); */ size_t fz_buffer_storage(fz_context *ctx, fz_buffer *buf, unsigned char **data); -struct fz_buffer_s -{ - int refs; - unsigned char *data; - size_t cap, len; - int unused_bits; - int shared; -}; +/* + fz_string_from_buffer: Ensure that a buffers data ends in a + 0 byte, and return a pointer to it. + + Returns pointer to data. +*/ +const char *fz_string_from_buffer(fz_context *ctx, fz_buffer *buf); /* fz_new_buffer: Create a new buffer. @@ -143,4 +142,20 @@ void fz_buffer_print_pdf_string(fz_context *ctx, fz_buffer *buffer, const char * */ void fz_md5_buffer(fz_context *ctx, fz_buffer *buffer, unsigned char digest[16]); +/* + fz_buffer_extract: Take ownership of buffer contents. + Performs the same task as fz_buffer_storage, but ownership of + the data buffer returns with this call. The buffer is left + empty. + + Note: Bad things may happen if this is called on a buffer with + multiple references that is being used from multiple threads. + + data: Pointer to place to retrieve data pointer. + + Returns length of stream. +*/ +size_t fz_buffer_extract(fz_context *ctx, fz_buffer *buf, unsigned char **data); + + #endif -- cgit v1.2.3