From e1e83141b57624c2ff3089ff09fe8d99a70473e9 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 19 Nov 2014 14:52:26 +0100 Subject: Add convenience fz_read_file function. Read the contents of a file into a fz_buffer in one go. --- source/fitz/stream-read.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'source') diff --git a/source/fitz/stream-read.c b/source/fitz/stream-read.c index de314fe4..3144974e 100644 --- a/source/fitz/stream-read.c +++ b/source/fitz/stream-read.c @@ -161,3 +161,28 @@ int fz_stream_meta(fz_stream *stm, int key, int size, void *ptr) return -1; return stm->meta(stm, key, size, ptr); } + +fz_buffer * +fz_read_file(fz_context *ctx, const char *filename) +{ + fz_stream *stm; + fz_buffer *buf = NULL; + + fz_var(buf); + + stm = fz_open_file(ctx, filename); + fz_try(ctx) + { + buf = fz_read_all(stm, 0); + } + fz_always(ctx) + { + fz_close(stm); + } + fz_catch(ctx) + { + fz_rethrow(ctx); + } + + return buf; +} -- cgit v1.2.3