From 7d5ff30c37c9e5b271fdb2b8cb3219068048322e Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Thu, 14 May 2015 17:12:42 +0100 Subject: 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. --- source/fitz/stream-prog.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source/fitz/stream-prog.c') 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); -- cgit v1.2.3