summaryrefslogtreecommitdiff
path: root/source/fitz/stream-open.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2013-12-13 16:29:18 +0000
committerRobin Watts <robin.watts@artifex.com>2014-01-02 20:04:42 +0000
commit651f13408c67a8392ad93adda079c096d8a6118c (patch)
tree4f6b68c2d53cdc75d1625649103cc29aedc9e2f7 /source/fitz/stream-open.c
parent0dde9978288535003ad9341613b9e4803339500d (diff)
downloadmupdf-651f13408c67a8392ad93adda079c096d8a6118c.tar.xz
Add rebinding for fz_streams.
Diffstat (limited to 'source/fitz/stream-open.c')
-rw-r--r--source/fitz/stream-open.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/source/fitz/stream-open.c b/source/fitz/stream-open.c
index 9e4dc8d4..f336a4e4 100644
--- a/source/fitz/stream-open.c
+++ b/source/fitz/stream-open.c
@@ -1,9 +1,20 @@
#include "mupdf/fitz.h"
+void fz_rebind_stream(fz_stream *stm, fz_context *ctx)
+{
+ if (stm == NULL || stm->ctx == ctx)
+ return;
+ do {
+ stm->ctx = ctx;
+ stm = (stm->rebind == NULL ? NULL : stm->rebind(stm));
+ } while (stm != NULL);
+}
+
fz_stream *
fz_new_stream(fz_context *ctx, void *state,
- int(*read)(fz_stream *stm, unsigned char *buf, int len),
- void(*close)(fz_context *ctx, void *state))
+ fz_stream_read_fn *read,
+ fz_stream_close_fn *close,
+ fz_stream_rebind_fn *rebind)
{
fz_stream *stm;
@@ -34,6 +45,7 @@ fz_new_stream(fz_context *ctx, void *state,
stm->read = read;
stm->close = close;
stm->seek = NULL;
+ stm->rebind = rebind;
stm->ctx = ctx;
return stm;
@@ -100,7 +112,7 @@ fz_open_fd(fz_context *ctx, int fd)
fz_try(ctx)
{
- stm = fz_new_stream(ctx, state, read_file, close_file);
+ stm = fz_new_stream(ctx, state, read_file, close_file, NULL);
}
fz_catch(ctx)
{
@@ -178,7 +190,7 @@ fz_open_buffer(fz_context *ctx, fz_buffer *buf)
fz_stream *stm;
fz_keep_buffer(ctx, buf);
- stm = fz_new_stream(ctx, buf, read_buffer, close_buffer);
+ stm = fz_new_stream(ctx, buf, read_buffer, close_buffer, NULL);
stm->seek = seek_buffer;
stm->bp = buf->data;
@@ -196,7 +208,7 @@ fz_open_memory(fz_context *ctx, unsigned char *data, int len)
{
fz_stream *stm;
- stm = fz_new_stream(ctx, NULL, read_buffer, close_buffer);
+ stm = fz_new_stream(ctx, NULL, read_buffer, close_buffer, NULL);
stm->seek = seek_buffer;
stm->bp = data;