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 | |
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')
-rw-r--r-- | source/fitz/bitmap.c | 2 | ||||
-rw-r--r-- | source/fitz/filter-basic.c | 4 | ||||
-rw-r--r-- | source/fitz/output-pcl.c | 4 | ||||
-rw-r--r-- | source/fitz/output-pwg.c | 4 | ||||
-rw-r--r-- | source/fitz/output.c | 2 | ||||
-rw-r--r-- | source/fitz/printf.c | 4 | ||||
-rw-r--r-- | source/fitz/stream-open.c | 14 | ||||
-rw-r--r-- | source/fitz/stream-prog.c | 18 | ||||
-rw-r--r-- | source/fitz/stream-read.c | 6 | ||||
-rw-r--r-- | source/fitz/string.c | 7 | ||||
-rw-r--r-- | source/fitz/unzip.c | 2 |
11 files changed, 35 insertions, 32 deletions
diff --git a/source/fitz/bitmap.c b/source/fitz/bitmap.c index 6357f7d7..4ae74932 100644 --- a/source/fitz/bitmap.c +++ b/source/fitz/bitmap.c @@ -56,7 +56,7 @@ fz_write_pbm(fz_context *ctx, fz_bitmap *bitmap, char *filename) unsigned char *p; int h, bytestride; - fp = fopen(filename, "wb"); + fp = fz_fopen(filename, "wb"); if (!fp) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); diff --git a/source/fitz/filter-basic.c b/source/fitz/filter-basic.c index eb9e838e..20bb6619 100644 --- a/source/fitz/filter-basic.c +++ b/source/fitz/filter-basic.c @@ -14,7 +14,7 @@ struct null_filter { fz_stream *chain; int remain; - int offset; + fz_off_t offset; unsigned char buffer[4096]; }; @@ -54,7 +54,7 @@ close_null(fz_context *ctx, void *state_) } fz_stream * -fz_open_null(fz_context *ctx, fz_stream *chain, int len, int offset) +fz_open_null(fz_context *ctx, fz_stream *chain, int len, fz_off_t offset) { struct null_filter *state; diff --git a/source/fitz/output-pcl.c b/source/fitz/output-pcl.c index a6dcc23b..1299e73d 100644 --- a/source/fitz/output-pcl.c +++ b/source/fitz/output-pcl.c @@ -795,7 +795,7 @@ fz_write_pcl(fz_context *ctx, fz_pixmap *pixmap, char *filename, int append, fz_ FILE *fp; fz_output *out = NULL; - fp = fopen(filename, append ? "ab" : "wb"); + fp = fz_fopen(filename, append ? "ab" : "wb"); if (!fp) { fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); @@ -824,7 +824,7 @@ fz_write_pcl_bitmap(fz_context *ctx, fz_bitmap *bitmap, char *filename, int appe FILE *fp; fz_output *out = NULL; - fp = fopen(filename, append ? "ab" : "wb"); + fp = fz_fopen(filename, append ? "ab" : "wb"); if (!fp) { fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); diff --git a/source/fitz/output-pwg.c b/source/fitz/output-pwg.c index 4af67c25..205966d3 100644 --- a/source/fitz/output-pwg.c +++ b/source/fitz/output-pwg.c @@ -263,7 +263,7 @@ fz_write_pwg(fz_context *ctx, fz_pixmap *pixmap, char *filename, int append, con FILE *fp; fz_output *out = NULL; - fp = fopen(filename, append ? "ab" : "wb"); + fp = fz_fopen(filename, append ? "ab" : "wb"); if (!fp) { fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); @@ -294,7 +294,7 @@ fz_write_pwg_bitmap(fz_context *ctx, fz_bitmap *bitmap, char *filename, int appe FILE *fp; fz_output *out = NULL; - fp = fopen(filename, append ? "ab" : "wb"); + fp = fz_fopen(filename, append ? "ab" : "wb"); if (!fp) { fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); diff --git a/source/fitz/output.c b/source/fitz/output.c index 52381377..027f66c3 100644 --- a/source/fitz/output.c +++ b/source/fitz/output.c @@ -45,7 +45,7 @@ fz_new_output_to_filename(fz_context *ctx, const char *filename) { fz_output *out = NULL; - FILE *file = fopen(filename, "wb"); + FILE *file = fz_fopen(filename, "wb"); if (!file) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); diff --git a/source/fitz/printf.c b/source/fitz/printf.c index 0e0f380a..c554540b 100644 --- a/source/fitz/printf.c +++ b/source/fitz/printf.c @@ -1,9 +1,5 @@ #include "mupdf/fitz.h" -/* This definition will be made elsewhere soon, but putting it here - * temporarily means the commits can be sensibly ordered. */ -typedef int fz_off_t; - static const char *fz_hex_digits = "0123456789abcdef"; struct fmtbuf diff --git a/source/fitz/stream-open.c b/source/fitz/stream-open.c index 10d94a09..4a3b69ad 100644 --- a/source/fitz/stream-open.c +++ b/source/fitz/stream-open.c @@ -81,13 +81,13 @@ static int next_file(fz_context *ctx, fz_stream *stm, int n) return *stm->rp++; } -static void seek_file(fz_context *ctx, fz_stream *stm, int offset, int whence) +static void seek_file(fz_context *ctx, fz_stream *stm, fz_off_t offset, int whence) { fz_file_stream *state = stm->state; - int n = fseek(state->file, offset, whence); + fz_off_t n = fz_fseek(state->file, offset, whence); if (n < 0) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot seek: %s", strerror(errno)); - stm->pos = ftell(state->file); + stm->pos = fz_ftell(state->file); stm->rp = state->buffer; stm->wp = state->buffer; } @@ -139,7 +139,7 @@ fz_open_file(fz_context *ctx, const char *name) 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); @@ -164,9 +164,9 @@ static int next_buffer(fz_context *ctx, fz_stream *stm, int max) return EOF; } -static void seek_buffer(fz_context *ctx, fz_stream *stm, int offset, int whence) +static void seek_buffer(fz_context *ctx, fz_stream *stm, fz_off_t offset, int whence) { - int pos = stm->pos - (stm->wp - stm->rp); + fz_off_t pos = stm->pos - (stm->wp - stm->rp); /* Convert to absolute pos */ if (whence == 1) { @@ -181,7 +181,7 @@ static void seek_buffer(fz_context *ctx, fz_stream *stm, int offset, int whence) offset = 0; if (offset > stm->pos) offset = stm->pos; - stm->rp += offset - pos; + stm->rp += (int)(offset - pos); } static void close_buffer(fz_context *ctx, void *state_) 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); diff --git a/source/fitz/stream-read.c b/source/fitz/stream-read.c index 75261ea5..e555314d 100644 --- a/source/fitz/stream-read.c +++ b/source/fitz/stream-read.c @@ -114,21 +114,21 @@ fz_read_line(fz_context *ctx, fz_stream *stm, char *mem, int n) *s = '\0'; } -int +fz_off_t fz_tell(fz_context *ctx, fz_stream *stm) { return stm->pos - (stm->wp - stm->rp); } void -fz_seek(fz_context *ctx, fz_stream *stm, int offset, int whence) +fz_seek(fz_context *ctx, fz_stream *stm, fz_off_t offset, int whence) { stm->avail = 0; /* Reset bit reading */ if (stm->seek) { if (whence == 1) { - offset = fz_tell(ctx, stm) + offset; + offset += fz_tell(ctx, stm); whence = 0; } stm->seek(ctx, stm, offset, whence); diff --git a/source/fitz/string.c b/source/fitz/string.c index 820a4426..b625dd4d 100644 --- a/source/fitz/string.c +++ b/source/fitz/string.c @@ -376,3 +376,10 @@ int fz_atoi(const char *s) return 0; return atoi(s); } + +fz_off_t fz_atoo(const char *s) +{ + if (s == NULL) + return 0; + return fz_atoo_imp(s); +} diff --git a/source/fitz/unzip.c b/source/fitz/unzip.c index 23028d42..ebbca66a 100644 --- a/source/fitz/unzip.c +++ b/source/fitz/unzip.c @@ -386,7 +386,7 @@ fz_has_archive_entry(fz_context *ctx, fz_archive *zip, const char *name) fz_strlcpy(path, zip->directory, sizeof path); fz_strlcat(path, "/", sizeof path); fz_strlcat(path, name, sizeof path); - file = fopen(path, "rb"); + file = fz_fopen(path, "rb"); if (file) fclose(file); return file != NULL; |