summaryrefslogtreecommitdiff
path: root/source/fitz/stream-read.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2014-11-19 14:52:26 +0100
committerTor Andersson <tor@ccxvii.net>2014-12-03 01:33:00 +0100
commite1e83141b57624c2ff3089ff09fe8d99a70473e9 (patch)
tree60b24d5d1787ae772929eeaffc98d8786fd2205b /source/fitz/stream-read.c
parent209544dea2f2e0b627a8b27a212681c1e9b8b7fc (diff)
downloadmupdf-e1e83141b57624c2ff3089ff09fe8d99a70473e9.tar.xz
Add convenience fz_read_file function.
Read the contents of a file into a fz_buffer in one go.
Diffstat (limited to 'source/fitz/stream-read.c')
-rw-r--r--source/fitz/stream-read.c25
1 files changed, 25 insertions, 0 deletions
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;
+}