diff options
author | Robin Watts <robin.watts@artifex.com> | 2015-05-14 17:12:42 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2015-05-15 13:06:56 +0100 |
commit | 7d5ff30c37c9e5b271fdb2b8cb3219068048322e (patch) | |
tree | 5f60d1d03235f2cff161207e00515c5a4a69ef73 /source/fitz/stream-prog.c | |
parent | 250e8a11e1debfbd9c4fc84ad895bf923aac135e (diff) | |
download | mupdf-7d5ff30c37c9e5b271fdb2b8cb3219068048322e.tar.xz |
Support pdf files larger than 2Gig.
If FZ_LARGEFILE is defined when building, MuPDF uses 64bit offsets
for files; this allows us to open streams larger than 2Gig.
The downsides to this are that:
* The xref entries are larger.
* All PDF ints are held as 64bit things rather than 32bit things
(to cope with /Prev entries, hint stream offsets etc).
* All file positions are stored as 64bits rather than 32.
The implementation works by detecting FZ_LARGEFILE. Some #ifdeffery
in fitz/system.h sets fz_off_t to either int or int64_t as appropriate,
and sets defines for fz_fopen, fz_fseek, fz_ftell etc as required.
These call the fseeko64 etc functions on linux (and so define
_LARGEFILE64_SOURCE) and the explicit 64bit functions on windows.
Diffstat (limited to 'source/fitz/stream-prog.c')
-rw-r--r-- | source/fitz/stream-prog.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/source/fitz/stream-prog.c b/source/fitz/stream-prog.c index 9911ddf6..de739c5c 100644 --- a/source/fitz/stream-prog.c +++ b/source/fitz/stream-prog.c @@ -20,8 +20,8 @@ show_progress(int av, int pos) typedef struct prog_state { FILE *file; - int length; - int available; + fz_off_t length; + fz_off_t available; int bps; clock_t start_time; unsigned char buffer[4096]; @@ -39,7 +39,7 @@ static int next_prog(fz_context *ctx, fz_stream *stm, int len) /* Simulate more data having arrived */ if (ps->available < ps->length) { - int av = (int)((float)(clock() - ps->start_time) * ps->bps / (CLOCKS_PER_SEC*8)); + fz_off_t av = (fz_off_t)((double)(clock() - ps->start_time) * ps->bps / (CLOCKS_PER_SEC*8)); if (av > ps->length) av = ps->length; ps->available = av; @@ -66,7 +66,7 @@ static int next_prog(fz_context *ctx, fz_stream *stm, int len) return *stm->rp++; } -static void seek_prog(fz_context *ctx, fz_stream *stm, int offset, int whence) +static void seek_prog(fz_context *ctx, fz_stream *stm, fz_off_t offset, int whence) { prog_state *ps = (prog_state *)stm->state; @@ -105,7 +105,7 @@ static void seek_prog(fz_context *ctx, fz_stream *stm, int offset, int whence) } } - if (fseek(ps->file, offset, whence) != 0) + if (fz_fseek(ps->file, offset, whence) != 0) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot seek: %s", strerror(errno)); stm->pos = offset; stm->wp = stm->rp; @@ -144,9 +144,9 @@ fz_open_file_ptr_progressive(fz_context *ctx, FILE *file, int bps) state->start_time = clock(); state->available = 0; - fseek(state->file, 0, SEEK_END); - state->length = ftell(state->file); - fseek(state->file, 0, SEEK_SET); + fz_fseek(state->file, 0, SEEK_END); + state->length = fz_ftell(state->file); + fz_fseek(state->file, 0, SEEK_SET); fz_try(ctx) { @@ -180,7 +180,7 @@ fz_open_file_progressive(fz_context *ctx, const char *name, int bps) f = _wfopen(wname, L"rb"); fz_free(ctx, wname); #else - f = fopen(name, "rb"); + f = fz_fopen(name, "rb"); #endif if (f == NULL) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open %s", name); |