summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2017-08-17 15:01:09 +0200
committerTor Andersson <tor.andersson@artifex.com>2017-11-01 13:08:56 +0100
commitf595e889b91a674eb94db7ca4d832da54f5194cd (patch)
tree273b4a7cc465477e428d0c628a19a61301baaae0
parent2910531c99e80bede06d2f1460459e8f6ce79961 (diff)
downloadmupdf-f595e889b91a674eb94db7ca4d832da54f5194cd.tar.xz
Use int64_t for public file API offsets.
Don't mess with conditional compilation with LARGEFILE -- always expose 64-bit file offsets in our public API.
-rw-r--r--Makerules5
-rw-r--r--docs/coding-style.html4
-rw-r--r--include/mupdf/fitz/filter.h2
-rw-r--r--include/mupdf/fitz/geometry.h5
-rw-r--r--include/mupdf/fitz/output.h22
-rw-r--r--include/mupdf/fitz/stream.h20
-rw-r--r--include/mupdf/fitz/system.h170
-rw-r--r--include/mupdf/pdf/document.h18
-rw-r--r--include/mupdf/pdf/object.h8
-rw-r--r--include/mupdf/pdf/parse.h2
-rw-r--r--include/mupdf/pdf/xref.h12
-rw-r--r--platform/java/Android.mk1
-rw-r--r--platform/java/mupdf_native.c4
-rw-r--r--platform/x11/curl_stream.c14
-rw-r--r--platform/x11/pdfapp.c8
-rw-r--r--platform/x11/win_main.c4
-rw-r--r--scripts/cmapdump.c17
-rw-r--r--source/fitz/color-icc-create.c2
-rw-r--r--source/fitz/draw-edge.c6
-rw-r--r--source/fitz/draw-edgebuffer.c4
-rw-r--r--source/fitz/draw-paint.c4
-rw-r--r--source/fitz/draw-rasterize.c2
-rw-r--r--source/fitz/error.c3
-rw-r--r--source/fitz/filter-basic.c12
-rw-r--r--source/fitz/filter-dct.c1
-rw-r--r--source/fitz/filter-jbig2.c2
-rw-r--r--source/fitz/glyph.c2
-rw-r--r--source/fitz/load-jpeg.c1
-rw-r--r--source/fitz/load-jpx.c8
-rw-r--r--source/fitz/load-jxr.c3
-rw-r--r--source/fitz/memory.c12
-rw-r--r--source/fitz/output-pcl.c3
-rw-r--r--source/fitz/output-pclm.c13
-rw-r--r--source/fitz/output-png.c2
-rw-r--r--source/fitz/output-psd.c10
-rw-r--r--source/fitz/output.c63
-rw-r--r--source/fitz/printf.c28
-rw-r--r--source/fitz/separation.c3
-rw-r--r--source/fitz/stext-device.c3
-rw-r--r--source/fitz/store.c1
-rw-r--r--source/fitz/stream-open.c68
-rw-r--r--source/fitz/stream-prog.c34
-rw-r--r--source/fitz/stream-read.c4
-rw-r--r--source/fitz/string.c4
-rw-r--r--source/fitz/time.c4
-rw-r--r--source/fitz/untar.c2
-rw-r--r--source/fitz/unzip.c4
-rw-r--r--source/fitz/xml.c2
-rw-r--r--source/fitz/zip.c2
-rw-r--r--source/gprf/gprf-doc.c14
-rw-r--r--source/gprf/gprf-skeleton.c2
-rw-r--r--source/helpers/mu-office-lib/mu-office-lib.c2
-rw-r--r--source/pdf/pdf-graft.c2
-rw-r--r--source/pdf/pdf-interpret.c2
-rw-r--r--source/pdf/pdf-lex.c2
-rw-r--r--source/pdf/pdf-object.c29
-rw-r--r--source/pdf/pdf-parse.c22
-rw-r--r--source/pdf/pdf-pkcs7.c4
-rw-r--r--source/pdf/pdf-repair.c6
-rw-r--r--source/pdf/pdf-stream.c8
-rw-r--r--source/pdf/pdf-write.c50
-rw-r--r--source/pdf/pdf-xref.c111
-rw-r--r--source/svg/svg-run.c3
-rw-r--r--source/tools/mjsgen.c4
-rw-r--r--source/tools/mudraw.c6
-rw-r--r--source/tools/muraster.c6
-rw-r--r--source/tools/pdfextract.c4
-rw-r--r--source/tools/pdfportfolio.c1
-rw-r--r--source/xps/xps-imp.h2
69 files changed, 425 insertions, 483 deletions
diff --git a/Makerules b/Makerules
index 1019e38d..56ba6ef4 100644
--- a/Makerules
+++ b/Makerules
@@ -8,7 +8,6 @@ OS := $(OS:Darwin=MACOS)
HAVE_LIBDL ?= yes
-
CFLAGS += -Wall -Wdeclaration-after-statement
ifeq (,$(findstring -fembed-bitcode,$(XCFLAGS)))
@@ -63,10 +62,6 @@ else
$(error unknown build setting: '$(build)')
endif
-ifeq "$(largefile)" "yes"
-CFLAGS += -DFZ_LARGEFILE
-endif
-
# Windows (MINGW) build doesn't use system libraries.
ifeq "$(OS)" "MINGW"
diff --git a/docs/coding-style.html b/docs/coding-style.html
index d9a1602d..66eefd39 100644
--- a/docs/coding-style.html
+++ b/docs/coding-style.html
@@ -83,9 +83,7 @@ In general:
<li> array sizes, string lengths, and allocations are measured using size_t.
size_t is 32bit in 32bit builds, and 64bit on all 64bit builds.
<li> buffers of data use unsigned chars (or uint8_t).
-<li> Offsets within files/streams are represented using fz_off_t.
- fz_off_t is 64bits in 64bit builds, or in 32bit builds with FZ_LARGEFILE defined.
- Otherwise it is a native int (so 32bit in 32bit builds).
+<li> Offsets within files/streams are represented using int64_t.
</ul>
<p>
diff --git a/include/mupdf/fitz/filter.h b/include/mupdf/fitz/filter.h
index 2f73f02f..dd3c295b 100644
--- a/include/mupdf/fitz/filter.h
+++ b/include/mupdf/fitz/filter.h
@@ -10,7 +10,7 @@
typedef struct fz_jbig2_globals_s fz_jbig2_globals;
fz_stream *fz_open_copy(fz_context *ctx, fz_stream *chain);
-fz_stream *fz_open_null(fz_context *ctx, fz_stream *chain, int len, fz_off_t offset);
+fz_stream *fz_open_null(fz_context *ctx, fz_stream *chain, int len, int64_t offset);
fz_stream *fz_open_concat(fz_context *ctx, int max, int pad);
void fz_concat_push_drop(fz_context *ctx, fz_stream *concat, fz_stream *chain); /* Ownership of chain is passed in */
fz_stream *fz_open_arc4(fz_context *ctx, fz_stream *chain, unsigned char *key, unsigned keylen);
diff --git a/include/mupdf/fitz/geometry.h b/include/mupdf/fitz/geometry.h
index d832248a..0667c3ee 100644
--- a/include/mupdf/fitz/geometry.h
+++ b/include/mupdf/fitz/geometry.h
@@ -47,8 +47,7 @@ float fz_atof(const char *s);
atoi that copes with NULL
*/
int fz_atoi(const char *s);
-
-fz_off_t fz_atoo(const char *s);
+int64_t fz_atoi64(const char *s);
/*
Some standard math functions, done as static inlines for speed.
@@ -90,7 +89,7 @@ static inline int fz_maxi(int a, int b)
return (a > b ? a : b);
}
-static inline fz_off_t fz_maxo(fz_off_t a, fz_off_t b)
+static inline int64_t fz_maxi64(int64_t a, int64_t b)
{
return (a > b ? a : b);
}
diff --git a/include/mupdf/fitz/output.h b/include/mupdf/fitz/output.h
index 2c7a53a8..c3c21c96 100644
--- a/include/mupdf/fitz/output.h
+++ b/include/mupdf/fitz/output.h
@@ -34,7 +34,7 @@ typedef void (fz_output_write_fn)(fz_context *ctx, void *state, const void *data
offset, whence: as defined for fs_seek_output.
*/
-typedef void (fz_output_seek_fn)(fz_context *ctx, void *state, fz_off_t offset, int whence);
+typedef void (fz_output_seek_fn)(fz_context *ctx, void *state, int64_t offset, int whence);
/*
fz_output_tell_fn: A function type for use when implementing
@@ -45,7 +45,7 @@ typedef void (fz_output_seek_fn)(fz_context *ctx, void *state, fz_off_t offset,
Returns the offset within the output stream.
*/
-typedef fz_off_t (fz_output_tell_fn)(fz_context *ctx, void *state);
+typedef int64_t (fz_output_tell_fn)(fz_context *ctx, void *state);
/*
fz_output_close_fn: A function type for use when implementing
@@ -80,17 +80,6 @@ struct fz_output_s
fz_output *fz_new_output(fz_context *ctx, void *state, fz_output_write_fn *write, fz_output_close_fn *close);
/*
- fz_new_output_with_file: Open an output stream that writes to a
- FILE *.
-
- file: The file to write to.
-
- close: non-zero if we should close the file when the fz_output
- is closed.
-*/
-fz_output *fz_new_output_with_file_ptr(fz_context *ctx, FILE *file, int close);
-
-/*
fz_new_output_with_path: Open an output stream that writes to a
given path.
@@ -156,14 +145,14 @@ void fz_write_vprintf(fz_context *ctx, fz_output *out, const char *fmt, va_list
Throw an error on unseekable outputs.
*/
-void fz_seek_output(fz_context *ctx, fz_output *out, fz_off_t off, int whence);
+void fz_seek_output(fz_context *ctx, fz_output *out, int64_t off, int whence);
/*
fz_tell_output: Return the current file position.
Throw an error on untellable outputs.
*/
-fz_off_t fz_tell_output(fz_context *ctx, fz_output *out);
+int64_t fz_tell_output(fz_context *ctx, fz_output *out);
/*
fz_drop_output: Close and free an output stream.
@@ -229,9 +218,8 @@ void fz_write_base64_buffer(fz_context *ctx, fz_output *out, fz_buffer *data, in
%C outputs a utf8 encoded int.
%M outputs a fz_matrix*. %R outputs a fz_rect*. %P outputs a fz_point*.
%q and %( output escaped strings in C/PDF syntax.
- %ll{d,u,x} indicates that the values are 64bit.
+ %l{d,u,x} indicates that the values are int64_t.
%z{d,u,x} indicates that the value is a size_t.
- %Z{d,u,x} indicates that the value is a fz_off_t.
user: An opaque pointer that is passed to the emit function.
emit: A function pointer called to emit output bytes as the string is being formatted.
diff --git a/include/mupdf/fitz/stream.h b/include/mupdf/fitz/stream.h
index be59a7a0..e336fd5d 100644
--- a/include/mupdf/fitz/stream.h
+++ b/include/mupdf/fitz/stream.h
@@ -33,7 +33,6 @@ typedef struct fz_stream_s fz_stream;
*/
fz_stream *fz_open_file(fz_context *ctx, const char *filename);
-fz_stream *fz_open_file_ptr_progressive(fz_context *ctx, FILE *file, int bps);
fz_stream *fz_open_file_progressive(fz_context *ctx, const char *filename, int bps);
/*
@@ -47,17 +46,6 @@ fz_stream *fz_open_file_progressive(fz_context *ctx, const char *filename, int b
fz_stream *fz_open_file_w(fz_context *ctx, const wchar_t *filename);
/*
- fz_open_file: Wrap an open file descriptor in a stream.
-
- file: An open file descriptor supporting bidirectional
- seeking. The stream will take ownership of the file
- descriptor, so it may not be modified or closed after the call
- to fz_open_file_ptr. When the stream is closed it will also close
- the file descriptor.
-*/
-fz_stream *fz_open_file_ptr(fz_context *ctx, FILE *file);
-
-/*
fz_open_memory: Open a block of memory as a stream.
data: Pointer to start of data block. Ownership of the data block is
@@ -107,7 +95,7 @@ void fz_drop_stream(fz_context *ctx, fz_stream *stm);
/*
fz_tell: return the current reading position within a stream
*/
-fz_off_t fz_tell(fz_context *ctx, fz_stream *stm);
+int64_t fz_tell(fz_context *ctx, fz_stream *stm);
/*
fz_seek: Seek within a stream.
@@ -118,7 +106,7 @@ fz_off_t fz_tell(fz_context *ctx, fz_stream *stm);
whence: From where the offset is measured (see fseek).
*/
-void fz_seek(fz_context *ctx, fz_stream *stm, fz_off_t offset, int whence);
+void fz_seek(fz_context *ctx, fz_stream *stm, int64_t offset, int whence);
/*
fz_read: Read from a stream into a given data block.
@@ -256,7 +244,7 @@ typedef void (fz_stream_close_fn)(fz_context *ctx, void *state);
The stream can find it's private state in stm->state.
*/
-typedef void (fz_stream_seek_fn)(fz_context *ctx, fz_stream *stm, fz_off_t offset, int whence);
+typedef void (fz_stream_seek_fn)(fz_context *ctx, fz_stream *stm, int64_t offset, int whence);
/*
fz_stream_meta_fn: A function type for use when implementing
@@ -273,7 +261,7 @@ struct fz_stream_s
int refs;
int error;
int eof;
- fz_off_t pos;
+ int64_t pos;
int avail;
int bits;
unsigned char *rp, *wp;
diff --git a/include/mupdf/fitz/system.h b/include/mupdf/fitz/system.h
index 255c61bb..7b426264 100644
--- a/include/mupdf/fitz/system.h
+++ b/include/mupdf/fitz/system.h
@@ -1,21 +1,6 @@
#ifndef MUPDF_FITZ_SYSTEM_H
#define MUPDF_FITZ_SYSTEM_H
-#if _MSC_VER >= 1400 /* MSVC 8 (Visual Studio 2005) or newer */
-#define FZ_LARGEFILE
-#endif
-
-/* The very first decision we need to make is, are we using the 64bit
- * file pointers code. This must happen before the stdio.h include. */
-#ifdef FZ_LARGEFILE
-/* Set _LARGEFILE64_SOURCE so that we know fopen64 et al will be declared. */
-#ifndef _WIN32
-#ifndef _LARGEFILE64_SOURCE
-#define _LARGEFILE64_SOURCE
-#endif
-#endif
-#endif
-
/* Turn on valgrind pacification in debug builds. */
#ifndef NDEBUG
#ifndef PACIFY_VALGRIND
@@ -27,21 +12,22 @@
Include the standard libc headers.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <stdarg.h>
-#include <string.h>
-#include <math.h>
-
-#include <assert.h>
-#include <errno.h>
-#include <limits.h> /* INT_MAX & co */
-#include <float.h> /* FLT_EPSILON, FLT_MAX & co */
-#include <fcntl.h> /* O_RDONLY & co */
-#include <time.h>
+#include <stddef.h> /* needed for size_t */
+#include <stdarg.h> /* needed for va_list vararg functions */
+#include <setjmp.h> /* needed for the try/catch macros */
-#include <setjmp.h>
+#if defined(_MSC_VER) && (_MSC_VER < 1700) /* MSVC older than VS2012 */
+typedef signed char int8_t;
+typedef short int int16_t;
+typedef int int32_t;
+typedef __int64 int64_t;
+typedef unsigned char uint8_t;
+typedef unsigned short int uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned __int64 uint64_t;
+#else
+#include <stdint.h> /* needed for int64_t */
+#endif
#include "mupdf/memento.h"
#include "mupdf/fitz/track-usage.h"
@@ -93,21 +79,23 @@
#endif
/* these constants mirror the corresponding macros in stdio.h */
-#define FZ_SEEK_SET 0
-#define FZ_SEEK_CUR 1
-#define FZ_SEEK_END 2
-#ifndef _MSC_VER
-/* For gettimeofday */
-#include <sys/time.h>
+#ifndef EOF
+#define EOF (-1)
+#endif
+#ifndef SEEK_SET
+#define SEEK_SET 0
+#endif
+#ifndef SEEK_CUR
+#define SEEK_CUR 1
+#endif
+#ifndef SEEK_END
+#define SEEK_END 2
#endif
#ifdef _MSC_VER /* Microsoft Visual C */
/* MSVC up to VS2012 */
#if _MSC_VER < 1800
-#define va_copy(a, oa) do { a=oa; } while (0)
-#define va_copy_end(a) do {} while(0)
-
static __inline int signbit(double x)
{
union
@@ -118,115 +106,31 @@ static __inline int signbit(double x)
u.d = x;
return (int)(u.i>>63);
}
-
-#else
-#define va_copy_end(a) va_end(a)
#endif
-typedef signed char int8_t;
-typedef short int int16_t;
-typedef int int32_t;
-typedef __int64 int64_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned short int uint16_t;
-typedef unsigned int uint32_t;
-typedef unsigned __int64 uint64_t;
-
#pragma warning( disable: 4244 ) /* conversion from X to Y, possible loss of data */
#pragma warning( disable: 4701 ) /* Potentially uninitialized local variable 'name' used */
#pragma warning( disable: 4996 ) /* 'function': was declared deprecated */
-#include <io.h>
-
-struct timeval;
-struct timezone;
-int gettimeofday(struct timeval *tv, struct timezone *tz);
-
-#if _MSC_VER < 1900 /* MSVC 2015 */
-#define snprintf msvc_snprintf
-#define vsnprintf msvc_vsnprintf
-static int msvc_vsnprintf(char *str, size_t size, const char *fmt, va_list ap)
-{
- int n;
- n = _vsnprintf(str, size, fmt, ap);
- str[size-1] = 0;
- return n;
-}
-static int msvc_snprintf(char *str, size_t size, const char *fmt, ...)
-{
- int n;
- va_list ap;
- va_start(ap, fmt);
- n = msvc_vsnprintf(str, size, fmt, ap);
- va_end(ap);
- return n;
-}
-#endif
-
#if _MSC_VER <= 1700 /* MSVC 2012 */
#define isnan(x) _isnan(x)
#define isinf(x) (!_finite(x))
#endif
#define hypotf _hypotf
-
-#define fz_fopen fz_fopen_utf8
-#define fz_remove fz_remove_utf8
+#define atoll _atoi64
+#define stat _stat
char *fz_utf8_from_wchar(const wchar_t *s);
wchar_t *fz_wchar_from_utf8(const char *s);
-FILE *fz_fopen_utf8(const char *name, const char *mode);
+/* really a FILE* but we don't want to include stdio.h here */
+void *fz_fopen_utf8(const char *name, const char *mode);
int fz_remove_utf8(const char *name);
char **fz_argv_from_wargv(int argc, wchar_t **wargv);
void fz_free_argv(int argc, char **argv);
-#define fseeko64 _fseeki64
-#define ftello64 _ftelli64
-#define atoll _atoi64
-
-#include <sys/stat.h>
-
-#define stat _stat
-
-#else /* Unix or close enough */
-
-#include <stdint.h>
-#include <unistd.h>
-#include <sys/stat.h>
-
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
-#define va_copy_end(a) va_end(a)
-
-#endif
-
-#ifndef fz_remove
-#define fz_remove remove
-#endif
-
-#ifdef FZ_LARGEFILE
-typedef int64_t fz_off_t;
-#define FZ_OFF_MAX 0x7fffffffffffffffLL
-#ifndef fz_fopen
-#define fz_fopen fopen64
-#endif
-#define fz_fseek fseeko64
-#define fz_ftell ftello64
-#define fz_atoo_imp atoll
-#else
-typedef int fz_off_t;
-#define FZ_OFF_MAX INT_MAX
-#ifndef fz_fopen
-#define fz_fopen fopen
-#endif
-#define fz_fseek fseek
-#define fz_ftell ftell
-#define fz_atoo_imp atoi
#endif
/* Cope with systems (such as Windows) with no S_ISDIR */
@@ -234,18 +138,8 @@ typedef int fz_off_t;
#define S_ISDIR(mode) ((mode) & S_IFDIR)
#endif
-/* Portable way to format a size_t */
-#if defined(_WIN64)
-#define FZ_FMT_zu "%llu"
-#elif defined(_WIN32)
-#define FZ_FMT_zu "%u"
-#else
-#define FZ_FMT_zu "%zu"
-#endif
-
#ifdef __ANDROID__
-#include <android/log.h>
-int fz_android_fprintf(FILE *file, const char *fmt, ...);
+int fz_android_fprintf(void *file, const char *fmt, ...);
#ifndef NDEBUG
/* Capture fprintf for stdout/stderr to the android logging
* stream. Only do this in debug builds as this implies a
@@ -333,6 +227,8 @@ extern void __gnu_mcount_nc(void);
#endif
#ifdef CLUSTER
+/* Include this first so our defines don't clash with the system definitions */
+#include <math.h>
/*
* Trig functions
*/
diff --git a/include/mupdf/pdf/document.h b/include/mupdf/pdf/document.h
index 0f4467e8..30cfba48 100644
--- a/include/mupdf/pdf/document.h
+++ b/include/mupdf/pdf/document.h
@@ -25,7 +25,7 @@ struct pdf_lexbuf_s
int size;
int base_size;
int len;
- fz_off_t i;
+ int64_t i;
float f;
char *scratch;
char buffer[PDF_LEXBUF_SMALL];
@@ -566,8 +566,8 @@ struct pdf_document_s
fz_stream *file;
int version;
- fz_off_t startxref;
- fz_off_t file_size;
+ int64_t startxref;
+ int64_t file_size;
pdf_crypt *crypt;
pdf_ocg_descriptor *ocg;
pdf_portfolio *portfolio;
@@ -593,7 +593,7 @@ struct pdf_document_s
/* State indicating which file parsing method we are using */
int file_reading_linearly;
- fz_off_t file_length;
+ int64_t file_length;
int linear_page_count;
pdf_obj *linear_obj; /* Linearized object (if used) */
@@ -601,7 +601,7 @@ struct pdf_document_s
int linear_page1_obj_num;
/* The state for the pdf_progressive_advance parser */
- fz_off_t linear_pos;
+ int64_t linear_pos;
int linear_page_num;
int hint_object_offset;
@@ -625,17 +625,17 @@ struct pdf_document_s
struct
{
int number; /* Page object number */
- fz_off_t offset; /* Offset of page object */
- fz_off_t index; /* Index into shared hint_shared_ref */
+ int64_t offset; /* Offset of page object */
+ int64_t index; /* Index into shared hint_shared_ref */
} *hint_page;
int *hint_shared_ref;
struct
{
int number; /* Object number of first object */
- fz_off_t offset; /* Offset of first object */
+ int64_t offset; /* Offset of first object */
} *hint_shared;
int hint_obj_offsets_max;
- fz_off_t *hint_obj_offsets;
+ int64_t *hint_obj_offsets;
int resources_localised;
diff --git a/include/mupdf/pdf/object.h b/include/mupdf/pdf/object.h
index 285acf4d..a1825eb2 100644
--- a/include/mupdf/pdf/object.h
+++ b/include/mupdf/pdf/object.h
@@ -13,8 +13,7 @@ typedef struct pdf_obj_s pdf_obj;
pdf_obj *pdf_new_null(fz_context *ctx, pdf_document *doc);
pdf_obj *pdf_new_bool(fz_context *ctx, pdf_document *doc, int b);
-pdf_obj *pdf_new_int(fz_context *ctx, pdf_document *doc, int i);
-pdf_obj *pdf_new_int_offset(fz_context *ctx, pdf_document *doc, fz_off_t off);
+pdf_obj *pdf_new_int(fz_context *ctx, pdf_document *doc, int64_t i);
pdf_obj *pdf_new_real(fz_context *ctx, pdf_document *doc, float f);
pdf_obj *pdf_new_name(fz_context *ctx, pdf_document *doc, const char *str);
pdf_obj *pdf_new_string(fz_context *ctx, pdf_document *doc, const char *str, size_t len);
@@ -84,7 +83,7 @@ void pdf_clean_obj(fz_context *ctx, pdf_obj *obj);
/* safe, silent failure, no error reporting on type mismatches */
int pdf_to_bool(fz_context *ctx, pdf_obj *obj);
int pdf_to_int(fz_context *ctx, pdf_obj *obj);
-fz_off_t pdf_to_offset(fz_context *ctx, pdf_obj *obj);
+int64_t pdf_to_int64(fz_context *ctx, pdf_obj *obj);
float pdf_to_real(fz_context *ctx, pdf_obj *obj);
const char *pdf_to_name(fz_context *ctx, pdf_obj *obj);
char *pdf_to_str_buf(fz_context *ctx, pdf_obj *obj);
@@ -155,7 +154,6 @@ fz_matrix *pdf_to_matrix(fz_context *ctx, pdf_obj *array, fz_matrix *mat);
pdf_document *pdf_get_indirect_document(fz_context *ctx, pdf_obj *obj);
pdf_document *pdf_get_bound_document(fz_context *ctx, pdf_obj *obj);
void pdf_set_str_len(fz_context *ctx, pdf_obj *obj, int newlen);
-void pdf_set_int(fz_context *ctx, pdf_obj *obj, int i);
-void pdf_set_int_offset(fz_context *ctx, pdf_obj *obj, fz_off_t i);
+void pdf_set_int(fz_context *ctx, pdf_obj *obj, int64_t i);
#endif
diff --git a/include/mupdf/pdf/parse.h b/include/mupdf/pdf/parse.h
index dc706f40..ed649234 100644
--- a/include/mupdf/pdf/parse.h
+++ b/include/mupdf/pdf/parse.h
@@ -29,7 +29,7 @@ pdf_token pdf_lex_no_string(fz_context *ctx, fz_stream *f, pdf_lexbuf *lexbuf);
pdf_obj *pdf_parse_array(fz_context *ctx, pdf_document *doc, fz_stream *f, pdf_lexbuf *buf);
pdf_obj *pdf_parse_dict(fz_context *ctx, pdf_document *doc, fz_stream *f, pdf_lexbuf *buf);
pdf_obj *pdf_parse_stm_obj(fz_context *ctx, pdf_document *doc, fz_stream *f, pdf_lexbuf *buf);
-pdf_obj *pdf_parse_ind_obj(fz_context *ctx, pdf_document *doc, fz_stream *f, pdf_lexbuf *buf, int *num, int *gen, fz_off_t *stm_ofs, int *try_repair);
+pdf_obj *pdf_parse_ind_obj(fz_context *ctx, pdf_document *doc, fz_stream *f, pdf_lexbuf *buf, int *num, int *gen, int64_t *stm_ofs, int *try_repair);
/*
pdf_append_token: print a lexed token to a buffer, growing if necessary
diff --git a/include/mupdf/pdf/xref.h b/include/mupdf/pdf/xref.h
index 971e5b8f..06633337 100644
--- a/include/mupdf/pdf/xref.h
+++ b/include/mupdf/pdf/xref.h
@@ -41,8 +41,8 @@ struct pdf_xref_entry_s
unsigned char flags; /* bit 0 = marked */
unsigned short gen; /* generation / objstm index */
int num; /* original object number (for decryption after renumbering) */
- fz_off_t ofs; /* file offset / objstm object number */
- fz_off_t stm_ofs; /* on-disk stream */
+ int64_t ofs; /* file offset / objstm object number */
+ int64_t stm_ofs; /* on-disk stream */
fz_buffer *stm_buf; /* in-memory stream (for updated objects) */
pdf_obj *obj; /* stored/cached object */
};
@@ -58,7 +58,7 @@ struct pdf_xref_subsec_s
{
pdf_xref_subsec *next;
int len;
- fz_off_t start;
+ int64_t start;
pdf_xref_entry *table;
};
@@ -70,7 +70,7 @@ struct pdf_xref_s
pdf_obj *pre_repair_trailer;
pdf_unsaved_sig *unsaved_sigs;
pdf_unsaved_sig **unsaved_sigs_end;
- fz_off_t end_ofs; /* file offset to end of xref */
+ int64_t end_ofs; /* file offset to end of xref */
};
pdf_xref_entry *pdf_cache_object(fz_context *ctx, pdf_document *doc, int num);
@@ -92,7 +92,7 @@ fz_stream *pdf_open_stream(fz_context *ctx, pdf_obj *ref);
fz_stream *pdf_open_inline_stream(fz_context *ctx, pdf_document *doc, pdf_obj *stmobj, int length, fz_stream *chain, fz_compression_params *params);
fz_compressed_buffer *pdf_load_compressed_stream(fz_context *ctx, pdf_document *doc, int num);
void pdf_load_compressed_inline_image(fz_context *ctx, pdf_document *doc, pdf_obj *dict, int length, fz_stream *cstm, int indexed, fz_compressed_image *image);
-fz_stream *pdf_open_stream_with_offset(fz_context *ctx, pdf_document *doc, int num, pdf_obj *dict, fz_off_t stm_ofs);
+fz_stream *pdf_open_stream_with_offset(fz_context *ctx, pdf_document *doc, int num, pdf_obj *dict, int64_t stm_ofs);
fz_stream *pdf_open_compressed_stream(fz_context *ctx, fz_compressed_buffer *);
fz_stream *pdf_open_contents_stream(fz_context *ctx, pdf_document *doc, pdf_obj *obj);
fz_buffer *pdf_load_stream_truncated(fz_context *ctx, pdf_document *doc, int num, int *truncated);
@@ -115,7 +115,7 @@ void pdf_mark_xref(fz_context *ctx, pdf_document *doc);
void pdf_clear_xref(fz_context *ctx, pdf_document *doc);
void pdf_clear_xref_to_mark(fz_context *ctx, pdf_document *doc);
-int pdf_repair_obj(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf, fz_off_t *stmofsp, int *stmlenp, pdf_obj **encrypt, pdf_obj **id, pdf_obj **page, fz_off_t *tmpofs, pdf_obj **root);
+int pdf_repair_obj(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf, int64_t *stmofsp, int *stmlenp, pdf_obj **encrypt, pdf_obj **id, pdf_obj **page, int64_t *tmpofs, pdf_obj **root);
pdf_obj *pdf_progressive_advance(fz_context *ctx, pdf_document *doc, int pagenum);
diff --git a/platform/java/Android.mk b/platform/java/Android.mk
index 465bd57b..1b880fac 100644
--- a/platform/java/Android.mk
+++ b/platform/java/Android.mk
@@ -53,6 +53,7 @@ LOCAL_C_INCLUDES := \
LOCAL_CFLAGS := \
-ffunction-sections -fdata-sections \
+ -D_FILE_OFFSET_BITS=32 \
-DTOFU_NOTO -DTOFU_CJK \
-DAA_BITS=8 \
diff --git a/platform/java/mupdf_native.c b/platform/java/mupdf_native.c
index 94ac6a34..e6d3629d 100644
--- a/platform/java/mupdf_native.c
+++ b/platform/java/mupdf_native.c
@@ -15,6 +15,10 @@
#include "mupdf_native.h" /* javah generated prototypes */
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
#ifdef HAVE_ANDROID
#include <android/log.h>
#include <android/bitmap.h>
diff --git a/platform/x11/curl_stream.c b/platform/x11/curl_stream.c
index db5a1413..e70607d5 100644
--- a/platform/x11/curl_stream.c
+++ b/platform/x11/curl_stream.c
@@ -324,7 +324,7 @@ stream_next(fz_context *ctx, fz_stream *stream, size_t len)
{
curl_stream_state *state = (curl_stream_state *)stream->state;
size_t len_read = 0;
- fz_off_t read_point = stream->pos;
+ int64_t read_point = stream->pos;
int block = read_point>>BLOCK_SHIFT;
size_t left_over = (-read_point) & (BLOCK_SIZE-1);
unsigned char *buf = state->public_buffer;
@@ -336,7 +336,7 @@ stream_next(fz_context *ctx, fz_stream *stream, size_t len)
len = sizeof(state->public_buffer);
if (state->content_length == 0)
- fz_throw(ctx, FZ_ERROR_TRYLATER, "read of a block we don't have (A) (offset=%d)", read_point);
+ fz_throw(ctx, FZ_ERROR_TRYLATER, "read of a block we don't have (A) (offset=%ld)", read_point);
if (state->map == NULL)
{
@@ -345,7 +345,7 @@ stream_next(fz_context *ctx, fz_stream *stream, size_t len)
if (read_point + len > state->current_fill_point)
{
stream->rp = stream->wp;
- fz_throw(ctx, FZ_ERROR_TRYLATER, "read of a block we don't have (B) (offset=%d)", read_point);
+ fz_throw(ctx, FZ_ERROR_TRYLATER, "read of a block we don't have (B) (offset=%ld)", read_point);
}
memcpy(buf, state->buffer + read_point, len);
stream->rp = buf;
@@ -370,7 +370,7 @@ stream_next(fz_context *ctx, fz_stream *stream, size_t len)
state->fill_point = block;
unlock(state);
stream->rp = stream->wp;
- fz_throw(ctx, FZ_ERROR_TRYLATER, "read of a block we don't have (C) (offset=%d)", read_point);
+ fz_throw(ctx, FZ_ERROR_TRYLATER, "read of a block we don't have (C) (offset=%ld)", read_point);
}
block++;
if (left_over > len)
@@ -391,7 +391,7 @@ stream_next(fz_context *ctx, fz_stream *stream, size_t len)
state->fill_point = block;
unlock(state);
stream->rp = stream->wp;
- fz_throw(ctx, FZ_ERROR_TRYLATER, "read of a block we don't have (D) (offset=%d)", read_point);
+ fz_throw(ctx, FZ_ERROR_TRYLATER, "read of a block we don't have (D) (offset=%ld)", read_point);
}
block++;
memcpy(buf, state->buffer + read_point, BLOCK_SIZE);
@@ -410,7 +410,7 @@ stream_next(fz_context *ctx, fz_stream *stream, size_t len)
state->fill_point = block;
unlock(state);
stream->rp = stream->wp;
- fz_throw(ctx, FZ_ERROR_TRYLATER, "read of a block we don't have (E) (offset=%d)", read_point);
+ fz_throw(ctx, FZ_ERROR_TRYLATER, "read of a block we don't have (E) (offset=%ld)", read_point);
}
memcpy(buf, state->buffer + read_point, len);
len_read += len;
@@ -456,7 +456,7 @@ static curl_stream_state hack;
static int hack_pos;
static void
-stream_seek(fz_context *ctx, fz_stream *stream, fz_off_t offset, int whence)
+stream_seek(fz_context *ctx, fz_stream *stream, int64_t offset, int whence)
{
curl_stream_state *state = (curl_stream_state *)stream->state;
diff --git a/platform/x11/pdfapp.c b/platform/x11/pdfapp.c
index 3fffd4ef..a5c524b4 100644
--- a/platform/x11/pdfapp.c
+++ b/platform/x11/pdfapp.c
@@ -520,7 +520,7 @@ static int gen_tmp_file(char *buf, int len)
for (i = 0; i < 10000; i++)
{
FILE *f;
- snprintf(name, buf+len-name, "tmp%04d", i);
+ sprintf(name, "tmp%04d", i);
f = fopen(buf, "r");
if (f == NULL)
return 1;
@@ -903,9 +903,9 @@ static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage, int repai
len = MAX_TITLE-strlen(buf2);
if (strlen(app->doctitle) > len)
{
- snprintf(buf, len-3, "%s", app->doctitle);
- strcat(buf, "...");
- strcat(buf, buf2);
+ fz_strlcpy(buf, app->doctitle, len-3);
+ fz_strlcat(buf, "...", MAX_TITLE);
+ fz_strlcat(buf, buf2, MAX_TITLE);
}
else
sprintf(buf, "%s%s", app->doctitle, buf2);
diff --git a/platform/x11/win_main.c b/platform/x11/win_main.c
index 67efdb9d..877f8c73 100644
--- a/platform/x11/win_main.c
+++ b/platform/x11/win_main.c
@@ -12,6 +12,10 @@
/* Include pdfapp.h *AFTER* the UNICODE defines */
#include "pdfapp.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
#ifndef WM_MOUSEWHEEL
#define WM_MOUSEWHEEL 0x020A
#endif
diff --git a/scripts/cmapdump.c b/scripts/cmapdump.c
index c82ac114..a59532e8 100644
--- a/scripts/cmapdump.c
+++ b/scripts/cmapdump.c
@@ -3,11 +3,15 @@
/* We never want to build memento versions of the cmapdump util */
#undef MEMENTO
-/* We never want large file access here */
-#undef FZ_LARGEFILE
-
-#include <stdio.h>
-#include <string.h>
+#ifndef _LARGEFILE64_SOURCE
+#ifdef _MSC_VER
+#if _MSC_VER >= 1400 /* MSVC 8 (Visual Studio 2005) or newer */
+#define _LARGEFILE64_SOURCE
+#endif
+#else
+#define _LARGEFILE64_SOURCE
+#endif
+#endif
#include "mupdf/fitz.h"
#include "mupdf/pdf.h"
@@ -32,6 +36,9 @@
#include "../source/pdf/pdf-cmap.c"
#include "../source/pdf/pdf-cmap-parse.c"
+#include <stdio.h>
+#include <string.h>
+
static void
clean(char *p)
{
diff --git a/source/fitz/color-icc-create.c b/source/fitz/color-icc-create.c
index 58acedf5..2a8da172 100644
--- a/source/fitz/color-icc-create.c
+++ b/source/fitz/color-icc-create.c
@@ -1,6 +1,8 @@
#include "mupdf/fitz.h"
#include "icc34.h"
+#include <string.h>
+
#define SAVEICCPROFILE 0
#define ICC_HEADER_SIZE 128
#define ICC_TAG_SIZE 12
diff --git a/source/fitz/draw-edge.c b/source/fitz/draw-edge.c
index 8510f216..244a4834 100644
--- a/source/fitz/draw-edge.c
+++ b/source/fitz/draw-edge.c
@@ -1,6 +1,12 @@
#include "mupdf/fitz.h"
#include "draw-imp.h"
+#include <assert.h>
+#include <limits.h>
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+
/*
* Global Edge List -- list of straight path segments for scan conversion
*
diff --git a/source/fitz/draw-edgebuffer.c b/source/fitz/draw-edgebuffer.c
index db2bbe3a..ffc892e1 100644
--- a/source/fitz/draw-edgebuffer.c
+++ b/source/fitz/draw-edgebuffer.c
@@ -1,6 +1,10 @@
#include "mupdf/fitz.h"
#include "draw-imp.h"
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
#undef DEBUG_SCAN_CONVERTER
/* Define ourselves a 'fixed' type for clarity */
diff --git a/source/fitz/draw-paint.c b/source/fitz/draw-paint.c
index 5735f615..43d546b3 100644
--- a/source/fitz/draw-paint.c
+++ b/source/fitz/draw-paint.c
@@ -2226,7 +2226,7 @@ fz_paint_pixmap(fz_pixmap * restrict dst, const fz_pixmap * restrict src, int al
if (dst->n - dst->alpha != src->n - src->alpha)
{
- fprintf(stderr, "fz_paint_pixmap - FIXME\n");
+ // fprintf(stderr, "fz_paint_pixmap - FIXME\n");
return;
}
assert(dst->n - dst->alpha == src->n - src->alpha);
@@ -2355,7 +2355,7 @@ fz_paint_pixmap_with_overprint(fz_pixmap * restrict dst, const fz_pixmap * restr
if (dst->n - dst->alpha != src->n - src->alpha)
{
- fprintf(stderr, "fz_paint_pixmap_with_overprint - FIXME\n");
+ // fprintf(stderr, "fz_paint_pixmap_with_overprint - FIXME\n");
return;
}
assert(dst->n - dst->alpha == src->n - src->alpha);
diff --git a/source/fitz/draw-rasterize.c b/source/fitz/draw-rasterize.c
index 2e399834..8b55b668 100644
--- a/source/fitz/draw-rasterize.c
+++ b/source/fitz/draw-rasterize.c
@@ -1,6 +1,8 @@
#include "mupdf/fitz.h"
#include "draw-imp.h"
+#include <string.h>
+
void fz_new_aa_context(fz_context *ctx)
{
#ifndef AA_BITS
diff --git a/source/fitz/error.c b/source/fitz/error.c
index 6820034d..0f371bc6 100644
--- a/source/fitz/error.c
+++ b/source/fitz/error.c
@@ -211,6 +211,7 @@ void fz_rethrow_if(fz_context *ctx, int err)
/* Android specific code to take fprintf to LOG */
#ifdef __ANDROID__
+#include <unistd.h>
#include <android/log.h>
#define LOG_TAG "libmupdf"
@@ -220,7 +221,7 @@ static int android_log_fill = 0;
static char android_log_buffer2[4096];
-int fz_android_fprintf(FILE *file, const char *fmt, ...)
+int fz_android_fprintf(void *file, const char *fmt, ...)
{
va_list args;
char *p, *q;
diff --git a/source/fitz/filter-basic.c b/source/fitz/filter-basic.c
index 959006f9..b64d8b66 100644
--- a/source/fitz/filter-basic.c
+++ b/source/fitz/filter-basic.c
@@ -16,7 +16,7 @@ struct null_filter
{
fz_stream *chain;
size_t remain;
- fz_off_t offset;
+ int64_t offset;
unsigned char buffer[4096];
};
@@ -41,8 +41,8 @@ next_null(fz_context *ctx, fz_stream *stm, size_t max)
return EOF;
state->chain->rp += n;
state->remain -= n;
- state->offset += (fz_off_t)n;
- stm->pos += (fz_off_t)n;
+ state->offset += (int64_t)n;
+ stm->pos += (int64_t)n;
return *stm->rp++;
}
@@ -56,7 +56,7 @@ close_null(fz_context *ctx, void *state_)
}
fz_stream *
-fz_open_null(fz_context *ctx, fz_stream *chain, int len, fz_off_t offset)
+fz_open_null(fz_context *ctx, fz_stream *chain, int len, int64_t offset)
{
struct null_filter *state = NULL;
@@ -106,7 +106,7 @@ next_concat(fz_context *ctx, fz_stream *stm, size_t max)
{
stm->rp = state->chain[state->current]->rp;
stm->wp = state->chain[state->current]->wp;
- stm->pos += (fz_off_t)n;
+ stm->pos += (int64_t)n;
return *stm->rp++;
}
else
@@ -581,7 +581,7 @@ next_arc4(fz_context *ctx, fz_stream *stm, size_t max)
stm->wp = state->buffer + n;
fz_arc4_encrypt(&state->arc4, stm->rp, state->chain->rp, n);
state->chain->rp += n;
- stm->pos += (fz_off_t)n;
+ stm->pos += (int64_t)n;
return *stm->rp++;
}
diff --git a/source/fitz/filter-dct.c b/source/fitz/filter-dct.c
index cdec5d3f..644d0dfc 100644
--- a/source/fitz/filter-dct.c
+++ b/source/fitz/filter-dct.c
@@ -1,5 +1,6 @@
#include "mupdf/fitz.h"
+#include <stdio.h>
#include <jpeglib.h>
#ifndef SHARE_JPEG
diff --git a/source/fitz/filter-jbig2.c b/source/fitz/filter-jbig2.c
index dd46269b..cbb70988 100644
--- a/source/fitz/filter-jbig2.c
+++ b/source/fitz/filter-jbig2.c
@@ -2,6 +2,8 @@
#ifdef HAVE_LURATECH
+#include <string.h>
+
#include <ldf_jb2.h>
typedef struct fz_jbig2d_s fz_jbig2d;
diff --git a/source/fitz/glyph.c b/source/fitz/glyph.c
index f5d97768..4c22b94b 100644
--- a/source/fitz/glyph.c
+++ b/source/fitz/glyph.c
@@ -57,6 +57,8 @@ fz_glyph_height(fz_context *ctx, fz_glyph *glyph)
}
#ifndef NDEBUG
+#include <stdio.h>
+
void
fz_dump_glyph(fz_glyph *glyph)
{
diff --git a/source/fitz/load-jpeg.c b/source/fitz/load-jpeg.c
index 810d49e0..b088325b 100644
--- a/source/fitz/load-jpeg.c
+++ b/source/fitz/load-jpeg.c
@@ -1,5 +1,6 @@
#include "mupdf/fitz.h"
+#include <stdio.h>
#include <string.h>
#include <limits.h>
diff --git a/source/fitz/load-jpx.c b/source/fitz/load-jpx.c
index f2751a58..3d7735d5 100644
--- a/source/fitz/load-jpx.c
+++ b/source/fitz/load-jpx.c
@@ -279,10 +279,10 @@ jpx_read_image(fz_context *ctx, fz_jpxd *state, const unsigned char *data, size_
{
err = JP2_Decompress_GetProp(doc, cJP2_Prop_Width, &widths[k], -1, k);
if (err != cJP2_Error_OK)
- fz_throw(ctx, FZ_ERROR_GENERIC, "cannot get width for component %ld: %d", k, (int) err);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot get width for component %d: %d", (int) k, (int) err);
err = JP2_Decompress_GetProp(doc, cJP2_Prop_Height, &heights[k], -1, k);
if (err != cJP2_Error_OK)
- fz_throw(ctx, FZ_ERROR_GENERIC, "cannot get height for component %ld: %d", k, (int) err);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot get height for component %d: %d", (int) k, (int) err);
state->width = fz_maxi(state->width, widths[k]);
state->height = fz_maxi(state->height, heights[k]);
@@ -380,10 +380,10 @@ jpx_read_image(fz_context *ctx, fz_jpxd *state, const unsigned char *data, size_
{
err = JP2_Decompress_GetProp(doc, cJP2_Prop_Bits_Per_Sample, &state->bpss[k], -1, k);
if (err != cJP2_Error_OK)
- fz_throw(ctx, FZ_ERROR_GENERIC, "cannot get bits per sample for component %ld: %d", k, (int) err);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot get bits per sample for component %d: %d", (int) k, (int) err);
err = JP2_Decompress_GetProp(doc, cJP2_Prop_Signed_Samples, &state->signs[k], -1, k);
if (err != cJP2_Error_OK)
- fz_throw(ctx, FZ_ERROR_GENERIC, "cannot get signed for component %ld: %d", k, (int) err);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot get signed for component %d: %d", (int) k, (int) err);
}
if (state->signs[k])
state->signs[k] = 1 << (state->bpss[k] - 1);
diff --git a/source/fitz/load-jxr.c b/source/fitz/load-jxr.c
index 29877575..789fcfe6 100644
--- a/source/fitz/load-jxr.c
+++ b/source/fitz/load-jxr.c
@@ -2,6 +2,9 @@
#ifdef HAVE_JPEGXR
+#include <math.h>
+#include <string.h>
+
#include <jpegxr.h>
struct info
diff --git a/source/fitz/memory.c b/source/fitz/memory.c
index 5aa8d78c..b935853d 100644
--- a/source/fitz/memory.c
+++ b/source/fitz/memory.c
@@ -98,7 +98,9 @@ fz_malloc_array_no_throw(fz_context *ctx, size_t count, size_t size)
if (count > SIZE_MAX / size)
{
- fprintf(stderr, "error: malloc of array (" FZ_FMT_zu " x " FZ_FMT_zu " bytes) failed (size_t overflow)", count, size);
+ char buf[100];
+ fz_snprintf(buf, sizeof buf, "error: malloc of array (%zu x %zu bytes) failed (size_t overflow)", count, size);
+ fprintf(stderr, "%s\n", buf);
return NULL;
}
@@ -137,7 +139,9 @@ fz_calloc_no_throw(fz_context *ctx, size_t count, size_t size)
if (count > SIZE_MAX / size)
{
- fprintf(stderr, "error: calloc (" FZ_FMT_zu " x " FZ_FMT_zu " bytes) failed (size_t overflow)\n", count, size);
+ char buf[100];
+ fz_snprintf(buf, sizeof buf, "error: calloc of array (%zu x %zu bytes) failed (size_t overflow)", count, size);
+ fprintf(stderr, "%s\n", buf);
return NULL;
}
@@ -180,7 +184,9 @@ fz_resize_array_no_throw(fz_context *ctx, void *p, size_t count, size_t size)
if (count > SIZE_MAX / size)
{
- fprintf(stderr, "error: resize array (" FZ_FMT_zu " x " FZ_FMT_zu " bytes) failed (size_t overflow)\n", count, size);
+ char buf[100];
+ fz_snprintf(buf, sizeof buf, "error: resize array (%zu x %zu bytes) failed (size_t overflow)", count, size);
+ fprintf(stderr, "%s\n", buf);
return NULL;
}
diff --git a/source/fitz/output-pcl.c b/source/fitz/output-pcl.c
index e3999b25..3898ac9c 100644
--- a/source/fitz/output-pcl.c
+++ b/source/fitz/output-pcl.c
@@ -1,7 +1,8 @@
#include "mupdf/fitz.h"
-#include <string.h>
#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
/* Lifted from ghostscript gdevjlm.h */
/*
diff --git a/source/fitz/output-pclm.c b/source/fitz/output-pclm.c
index 0d1f728c..8f05f3bf 100644
--- a/source/fitz/output-pclm.c
+++ b/source/fitz/output-pclm.c
@@ -2,7 +2,6 @@
#include <string.h>
#include <limits.h>
-#include <zlib.h>
const char *fz_pclm_write_options_usage =
"PCLm output options:\n"
@@ -29,7 +28,7 @@ fz_parse_pclm_options(fz_context *ctx, fz_pclm_options *opts, const char *args)
}
if (fz_has_option(ctx, args, "strip-height", &val))
{
- int i = atoi(val);
+ int i = fz_atoi(val);
if (i <= 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "Unsupported PCLm strip height %d (suggest 16)", i);
opts->strip_height = i;
@@ -65,7 +64,7 @@ typedef struct pclm_band_writer_s
int obj_num;
int xref_max;
- fz_off_t *xref;
+ int64_t *xref;
int pages;
int page_max;
int *page_obj;
@@ -77,7 +76,7 @@ typedef struct pclm_band_writer_s
static int
new_obj(fz_context *ctx, pclm_band_writer *writer)
{
- fz_off_t pos = fz_tell_output(ctx, writer->super.out);
+ int64_t pos = fz_tell_output(ctx, writer->super.out);
if (writer->obj_num >= writer->xref_max)
{
@@ -192,7 +191,7 @@ flush_strip(fz_context *ctx, pclm_band_writer *writer, int fill)
/* Buffer is full, compress it and write it. */
if (writer->options.compress)
{
- uLongf destLen = writer->complen;
+ size_t destLen = writer->complen;
fz_deflate(ctx, writer->compbuf, &destLen, data, len, FZ_DEFLATE_DEFAULT);
len = destLen;
data = writer->compbuf;
@@ -245,7 +244,7 @@ pclm_drop_band_writer(fz_context *ctx, fz_band_writer *writer_)
/* We actually do the trailer writing in the drop */
if (writer->xref_max > 2)
{
- fz_off_t t_pos;
+ int64_t t_pos;
/* Catalog */
writer->xref[1] = fz_tell_output(ctx, out);
@@ -264,7 +263,7 @@ pclm_drop_band_writer(fz_context *ctx, fz_band_writer *writer_)
fz_write_printf(ctx, out, "xref\n0 %d\n0000000000 65535 f \n", writer->obj_num);
for (i = 1; i < writer->obj_num; i++)
fz_write_printf(ctx, out, "%010zd 00000 n \n", writer->xref[i]);
- fz_write_printf(ctx, out, "trailer\n<<\n/Size %d\n/Root 1 0 R\n>>\nstartxref\n%Zd\n%%%%EOF\n", writer->obj_num, t_pos);
+ fz_write_printf(ctx, out, "trailer\n<<\n/Size %d\n/Root 1 0 R\n>>\nstartxref\n%ld\n%%%%EOF\n", writer->obj_num, t_pos);
}
fz_free(ctx, writer->stripbuf);
diff --git a/source/fitz/output-png.c b/source/fitz/output-png.c
index d21bc59b..709d65f0 100644
--- a/source/fitz/output-png.c
+++ b/source/fitz/output-png.c
@@ -1,5 +1,7 @@
#include "mupdf/fitz.h"
+#include <string.h>
+
#include <zlib.h>
static inline void big32(unsigned char *buf, unsigned int v)
diff --git a/source/fitz/output-psd.c b/source/fitz/output-psd.c
index d39051dd..37d51bc8 100644
--- a/source/fitz/output-psd.c
+++ b/source/fitz/output-psd.c
@@ -1,5 +1,7 @@
#include "mupdf/fitz.h"
+#include <string.h>
+
void
fz_save_pixmap_as_psd(fz_context *ctx, fz_pixmap *pixmap, const char *filename)
{
@@ -118,7 +120,7 @@ psd_write_header(fz_context *ctx, fz_band_writer *writer_, const fz_colorspace *
size_t len2;
if (name == NULL)
{
- sprintf(text, "Spot%d", i-4);
+ fz_snprintf(text, sizeof text, "Spot%d", i-4);
name = text;
}
len2 = strlen(name);
@@ -147,7 +149,7 @@ psd_write_header(fz_context *ctx, fz_band_writer *writer_, const fz_colorspace *
char text[32];
if (name == NULL)
{
- sprintf(text, "Spot%d", i-4);
+ fz_snprintf(text, sizeof text, "Spot%d", i-4);
name = text;
}
len2 = strlen(name);
@@ -277,9 +279,9 @@ psd_write_band(fz_context *ctx, fz_band_writer *writer_, int stride, int band_st
fz_write_data(ctx, out, buffer, b - buffer);
b = buffer;
}
- fz_seek_output(ctx, out, plane_inc, FZ_SEEK_CUR);
+ fz_seek_output(ctx, out, plane_inc, SEEK_CUR);
}
- fz_seek_output(ctx, out, w * h * (1-n), FZ_SEEK_CUR);
+ fz_seek_output(ctx, out, w * h * (1-n), SEEK_CUR);
}
static void
diff --git a/source/fitz/output.c b/source/fitz/output.c
index 44efc414..06b25be5 100644
--- a/source/fitz/output.c
+++ b/source/fitz/output.c
@@ -1,3 +1,8 @@
+#define _LARGEFILE_SOURCE
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#endif
+
#include "mupdf/fitz.h"
#include "fitz-imp.h"
@@ -118,19 +123,27 @@ std_write(fz_context *ctx, void *opaque, const void *buffer, size_t count)
}
static void
-file_seek(fz_context *ctx, void *opaque, fz_off_t off, int whence)
+file_seek(fz_context *ctx, void *opaque, int64_t off, int whence)
{
FILE *file = opaque;
- int n = fz_fseek(file, off, whence);
+#if defined(_WIN32) || defined(_WIN64)
+ int n = _fseeki64(file, off, whence);
+#else
+ int n = fseeko(file, off, whence);
+#endif
if (n < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot fseek: %s", strerror(errno));
}
-static fz_off_t
+static int64_t
file_tell(fz_context *ctx, void *opaque)
{
FILE *file = opaque;
- fz_off_t off = fz_ftell(file);
+#if defined(_WIN32) || defined(_WIN64)
+ int64_t off = _ftelli64(file);
+#else
+ int64_t off = ftello(file);
+#endif
if (off == -1)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot ftell: %s", strerror(errno));
return off;
@@ -167,35 +180,41 @@ fz_new_output(fz_context *ctx, void *state, fz_output_write_fn *write, fz_output
}
fz_output *
-fz_new_output_with_file_ptr(fz_context *ctx, FILE *file, int close)
-{
- fz_output *out = fz_new_output(ctx, file, file_write, close ? file_close : NULL);
- out->seek = file_seek;
- out->tell = file_tell;
- return out;
-}
-
-fz_output *
fz_new_output_with_path(fz_context *ctx, const char *filename, int append)
{
FILE *file;
+ fz_output *out;
if (!strcmp(filename, "/dev/null") || !fz_strcasecmp(filename, "nul:"))
return NULL;
+#if defined(_WIN32) || defined(_WIN64)
/* Ensure we create a brand new file. We don't want to clobber our old file. */
if (!append)
{
- if (fz_remove(filename) < 0)
+ if (fz_remove_utf8(filename) < 0)
if (errno != ENOENT)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot remove file '%s': %s", filename, strerror(errno));
}
-
- file = fz_fopen(filename, append ? "ab" : "wb");
+ file = fz_fopen_utf8(filename, "rb");
+#else
+ /* Ensure we create a brand new file. We don't want to clobber our old file. */
+ if (!append)
+ {
+ if (remove(filename) < 0)
+ if (errno != ENOENT)
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot remove file '%s': %s", filename, strerror(errno));
+ }
+ file = fopen(filename, append ? "ab" : "wb");
+#endif
if (!file)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno));
- return fz_new_output_with_file_ptr(ctx, file, 1);
+ out = fz_new_output(ctx, file, file_write, file_close);
+ out->seek = file_seek;
+ out->tell = file_tell;
+
+ return out;
}
static void
@@ -206,16 +225,16 @@ buffer_write(fz_context *ctx, void *opaque, const void *data, size_t len)
}
static void
-buffer_seek(fz_context *ctx, void *opaque, fz_off_t off, int whence)
+buffer_seek(fz_context *ctx, void *opaque, int64_t off, int whence)
{
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot seek in buffer: %s", strerror(errno));
}
-static fz_off_t
+static int64_t
buffer_tell(fz_context *ctx, void *opaque)
{
fz_buffer *buffer = opaque;
- return (fz_off_t)buffer->len;
+ return (int64_t)buffer->len;
}
static void
@@ -245,7 +264,7 @@ fz_drop_output(fz_context *ctx, fz_output *out)
}
void
-fz_seek_output(fz_context *ctx, fz_output *out, fz_off_t off, int whence)
+fz_seek_output(fz_context *ctx, fz_output *out, int64_t off, int whence)
{
if (!out) return;
if (out->seek == NULL)
@@ -253,7 +272,7 @@ fz_seek_output(fz_context *ctx, fz_output *out, fz_off_t off, int whence)
out->seek(ctx, out->state, off, whence);
}
-fz_off_t
+int64_t
fz_tell_output(fz_context *ctx, fz_output *out)
{
if (!out) return 0;
diff --git a/source/fitz/printf.c b/source/fitz/printf.c
index 3fe8c7e4..bbdda93f 100644
--- a/source/fitz/printf.c
+++ b/source/fitz/printf.c
@@ -5,6 +5,22 @@
#include <stdarg.h>
#include <stdio.h>
+#ifdef _MSC_VER
+#if _MSC_VER < 1500 /* MSVC 2008 */
+int snprintf(char *s, size_t n, const char *fmt, ...)
+{
+ int r;
+ va_list ap;
+ va_start(ap, fmt);
+ r = vsprintf(s, fmt, ap);
+ va_end(ap);
+ return r;
+}
+#else if _MSC_VER < 1900 /* MSVC 2015 */
+#define snprintf _snprintf
+#endif
+#endif
+
static const char *fz_hex_digits = "0123456789abcdef";
struct fmtbuf
@@ -290,11 +306,7 @@ fz_format_string(fz_context *ctx, void *user, void (*emit)(fz_context *ctx, void
bits = 0;
if (c == 'l') {
c = *fmt++;
- bits = sizeof(long) * 8;
- if (c == 'l') {
- c = *fmt++;
- bits = 64;
- }
+ bits = sizeof(int64_t) * 8;
if (c == 0)
break;
}
@@ -310,12 +322,6 @@ fz_format_string(fz_context *ctx, void *user, void (*emit)(fz_context *ctx, void
if (c == 0)
break;
}
- if (c == 'Z') {
- c = *fmt++;
- bits = sizeof(fz_off_t) * 8;
- if (c == 0)
- break;
- }
switch (c) {
default:
diff --git a/source/fitz/separation.c b/source/fitz/separation.c
index 8a154347..82f6ead7 100644
--- a/source/fitz/separation.c
+++ b/source/fitz/separation.c
@@ -1,5 +1,8 @@
#include "mupdf/fitz.h"
+#include <assert.h>
+#include <string.h>
+
enum
{
FZ_SEPARATION_DISABLED_RENDER = 3
diff --git a/source/fitz/stext-device.c b/source/fitz/stext-device.c
index 069caa9f..117cd72e 100644
--- a/source/fitz/stext-device.c
+++ b/source/fitz/stext-device.c
@@ -3,8 +3,7 @@
#include <math.h>
#include <float.h>
-
-#include <stdio.h> /* for debug printing */
+#include <string.h>
/* Extract text into blocks and lines. */
diff --git a/source/fitz/store.c b/source/fitz/store.c
index bb9426ba..e2303fd3 100644
--- a/source/fitz/store.c
+++ b/source/fitz/store.c
@@ -1,6 +1,7 @@
#include "mupdf/fitz.h"
#include <assert.h>
+#include <limits.h>
#include <stdio.h>
typedef struct fz_item_s fz_item;
diff --git a/source/fitz/stream-open.c b/source/fitz/stream-open.c
index d7cff535..ffd61b66 100644
--- a/source/fitz/stream-open.c
+++ b/source/fitz/stream-open.c
@@ -1,3 +1,9 @@
+#define _LARGEFILE_SOURCE
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#endif
+
+#include "mupdf/fitz.h"
#include "fitz-imp.h"
#include <string.h>
@@ -7,7 +13,12 @@
int
fz_file_exists(fz_context *ctx, const char *path)
{
- FILE *file = fz_fopen(path, "rb");
+ FILE *file;
+#if defined(_WIN32) || defined(_WIN64)
+ file = fz_fopen_utf8(path, "rb");
+#else
+ file = fopen(path, "rb");
+#endif
if (file)
fclose(file);
return !!file;
@@ -66,6 +77,9 @@ fz_drop_stream(fz_context *ctx, fz_stream *stm)
/* File stream */
+// TODO: WIN32: HANDLE CreateFileW(), etc.
+// TODO: POSIX: int creat(), read(), write(), lseeko, etc.
+
typedef struct fz_file_stream_s
{
FILE *file;
@@ -82,20 +96,28 @@ static int next_file(fz_context *ctx, fz_stream *stm, size_t n)
fz_throw(ctx, FZ_ERROR_GENERIC, "read error: %s", strerror(errno));
stm->rp = state->buffer;
stm->wp = state->buffer + n;
- stm->pos += (fz_off_t)n;
+ stm->pos += (int64_t)n;
if (n == 0)
return EOF;
return *stm->rp++;
}
-static void seek_file(fz_context *ctx, fz_stream *stm, fz_off_t offset, int whence)
+static void seek_file(fz_context *ctx, fz_stream *stm, int64_t offset, int whence)
{
fz_file_stream *state = stm->state;
- fz_off_t n = fz_fseek(state->file, offset, whence);
+#if defined(_WIN32) || defined(_WIN64)
+ int64_t n = _fseeki64(state->file, offset, whence);
+#else
+ int64_t n = fseeko(state->file, offset, whence);
+#endif
if (n < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot seek: %s", strerror(errno));
- stm->pos = fz_ftell(state->file);
+#if defined(_WIN32) || defined(_WIN64)
+ stm->pos = _ftelli64(state->file);
+#else
+ stm->pos = ftello(state->file);
+#endif
stm->rp = state->buffer;
stm->wp = state->buffer;
}
@@ -109,7 +131,7 @@ static void close_file(fz_context *ctx, void *state_)
fz_free(ctx, state);
}
-fz_stream *
+static fz_stream *
fz_open_file_ptr(fz_context *ctx, FILE *file)
{
fz_stream *stm;
@@ -125,35 +147,25 @@ fz_open_file_ptr(fz_context *ctx, FILE *file)
fz_stream *
fz_open_file(fz_context *ctx, const char *name)
{
- FILE *f;
+ FILE *file;
#if defined(_WIN32) || defined(_WIN64)
- char *s = (char*)name;
- wchar_t *wname, *d;
- int c;
- d = wname = fz_malloc(ctx, (strlen(name)+1) * sizeof(wchar_t));
- while (*s) {
- s += fz_chartorune(&c, s);
- *d++ = c;
- }
- *d = 0;
- f = _wfopen(wname, L"rb");
- fz_free(ctx, wname);
+ file = fz_fopen_utf8(name, "rb");
#else
- f = fz_fopen(name, "rb");
+ file = fopen(name, "rb");
#endif
- if (f == NULL)
+ if (file == NULL)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open %s: %s", name, strerror(errno));
- return fz_open_file_ptr(ctx, f);
+ return fz_open_file_ptr(ctx, file);
}
#if defined(_WIN32) || defined(_WIN64)
fz_stream *
fz_open_file_w(fz_context *ctx, const wchar_t *name)
{
- FILE *f = _wfopen(name, L"rb");
- if (f == NULL)
+ FILE *file = _wfopen(name, L"rb");
+ if (file == NULL)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file %ls: %s", name, strerror(errno));
- return fz_open_file_ptr(ctx, f);
+ return fz_open_file_ptr(ctx, file);
}
#endif
@@ -164,9 +176,9 @@ static int next_buffer(fz_context *ctx, fz_stream *stm, size_t max)
return EOF;
}
-static void seek_buffer(fz_context *ctx, fz_stream *stm, fz_off_t offset, int whence)
+static void seek_buffer(fz_context *ctx, fz_stream *stm, int64_t offset, int whence)
{
- fz_off_t pos = stm->pos - (stm->wp - stm->rp);
+ int64_t pos = stm->pos - (stm->wp - stm->rp);
/* Convert to absolute pos */
if (whence == 1)
{
@@ -202,7 +214,7 @@ fz_open_buffer(fz_context *ctx, fz_buffer *buf)
stm->rp = buf->data;
stm->wp = buf->data + buf->len;
- stm->pos = (fz_off_t)buf->len;
+ stm->pos = (int64_t)buf->len;
return stm;
}
@@ -218,7 +230,7 @@ fz_open_memory(fz_context *ctx, const unsigned char *data, size_t len)
stm->rp = (unsigned char *)data;
stm->wp = (unsigned char *)data + len;
- stm->pos = (fz_off_t)len;
+ stm->pos = (int64_t)len;
return stm;
}
diff --git a/source/fitz/stream-prog.c b/source/fitz/stream-prog.c
index eeb33242..89158832 100644
--- a/source/fitz/stream-prog.c
+++ b/source/fitz/stream-prog.c
@@ -10,8 +10,8 @@
typedef struct prog_state
{
FILE *file;
- fz_off_t length;
- fz_off_t available;
+ int64_t length;
+ int64_t available;
int bps;
clock_t start_time;
unsigned char buffer[4096];
@@ -29,7 +29,7 @@ static int next_prog(fz_context *ctx, fz_stream *stm, size_t len)
/* Simulate more data having arrived */
if (ps->available < ps->length)
{
- fz_off_t av = (fz_off_t)((float)(clock() - ps->start_time) * ps->bps / (CLOCKS_PER_SEC*8));
+ int64_t av = (int64_t)((float)(clock() - ps->start_time) * ps->bps / (CLOCKS_PER_SEC*8));
if (av > ps->length)
av = ps->length;
ps->available = av;
@@ -47,13 +47,13 @@ static int next_prog(fz_context *ctx, fz_stream *stm, size_t len)
fz_throw(ctx, FZ_ERROR_GENERIC, "read error: %s", strerror(errno));
stm->rp = ps->buffer + stm->pos;
stm->wp = ps->buffer + stm->pos + n;
- stm->pos += (fz_off_t)n;
+ stm->pos += (int64_t)n;
if (n == 0)
return EOF;
return *stm->rp++;
}
-static void seek_prog(fz_context *ctx, fz_stream *stm, fz_off_t offset, int whence)
+static void seek_prog(fz_context *ctx, fz_stream *stm, int64_t offset, int whence)
{
prog_state *ps = (prog_state *)stm->state;
@@ -83,7 +83,7 @@ static void seek_prog(fz_context *ctx, fz_stream *stm, fz_off_t offset, int when
fz_throw(ctx, FZ_ERROR_TRYLATER, "Not enough data to seek to offset yet");
}
- if (fz_fseek(ps->file, offset, whence) != 0)
+ if (fseek(ps->file, offset, whence) != 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot seek: %s", strerror(errno));
stm->pos = offset;
stm->wp = stm->rp;
@@ -110,7 +110,7 @@ static int meta_prog(fz_context *ctx, fz_stream *stm, int key, int size, void *p
return -1;
}
-fz_stream *
+static fz_stream *
fz_open_file_ptr_progressive(fz_context *ctx, FILE *file, int bps)
{
fz_stream *stm;
@@ -122,9 +122,9 @@ fz_open_file_ptr_progressive(fz_context *ctx, FILE *file, int bps)
state->start_time = clock();
state->available = 0;
- fz_fseek(state->file, 0, SEEK_END);
- state->length = fz_ftell(state->file);
- fz_fseek(state->file, 0, SEEK_SET);
+ fseek(state->file, 0, SEEK_END);
+ state->length = ftell(state->file);
+ fseek(state->file, 0, SEEK_SET);
stm = fz_new_stream(ctx, state, next_prog, close_prog);
stm->seek = seek_prog;
@@ -138,19 +138,9 @@ fz_open_file_progressive(fz_context *ctx, const char *name, int bps)
{
FILE *f;
#if defined(_WIN32) || defined(_WIN64)
- char *s = (char*)name;
- wchar_t *wname, *d;
- int c;
- d = wname = fz_malloc(ctx, (strlen(name)+1) * sizeof(wchar_t));
- while (*s) {
- s += fz_chartorune(&c, s);
- *d++ = c;
- }
- *d = 0;
- f = _wfopen(wname, L"rb");
- fz_free(ctx, wname);
+ f = fz_fopen_utf8(name, "rb");
#else
- f = fz_fopen(name, "rb");
+ f = 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 118589f9..1a2bda01 100644
--- a/source/fitz/stream-read.c
+++ b/source/fitz/stream-read.c
@@ -137,14 +137,14 @@ fz_read_line(fz_context *ctx, fz_stream *stm, char *mem, size_t n)
return (s == mem && c == EOF) ? NULL : mem;
}
-fz_off_t
+int64_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, fz_off_t offset, int whence)
+fz_seek(fz_context *ctx, fz_stream *stm, int64_t offset, int whence)
{
stm->avail = 0; /* Reset bit reading */
if (stm->seek)
diff --git a/source/fitz/string.c b/source/fitz/string.c
index e3c62d02..dbcc2c22 100644
--- a/source/fitz/string.c
+++ b/source/fitz/string.c
@@ -459,11 +459,11 @@ int fz_atoi(const char *s)
return atoi(s);
}
-fz_off_t fz_atoo(const char *s)
+int64_t fz_atoi64(const char *s)
{
if (s == NULL)
return 0;
- return fz_atoo_imp(s);
+ return atoll(s);
}
int fz_is_page_range(fz_context *ctx, const char *s)
diff --git a/source/fitz/time.c b/source/fitz/time.c
index 99c0952c..9fb8cfa4 100644
--- a/source/fitz/time.c
+++ b/source/fitz/time.c
@@ -2,6 +2,8 @@
#include "mupdf/fitz.h"
+#include <stdio.h>
+#include <errno.h>
#include <time.h>
#include <windows.h>
@@ -79,7 +81,7 @@ fz_wchar_from_utf8(const char *s)
return r;
}
-FILE *
+void *
fz_fopen_utf8(const char *name, const char *mode)
{
wchar_t *wname, *wmode;
diff --git a/source/fitz/untar.c b/source/fitz/untar.c
index d8ae6336..ad93e1e3 100644
--- a/source/fitz/untar.c
+++ b/source/fitz/untar.c
@@ -59,7 +59,7 @@ static void ensure_tar_entries(fz_context *ctx, fz_tar_archive *tar)
tar->count = 0;
- fz_seek(ctx, file, 0, FZ_SEEK_SET);
+ fz_seek(ctx, file, 0, SEEK_SET);
while (1)
{
diff --git a/source/fitz/unzip.c b/source/fitz/unzip.c
index 0bcce0fd..c5798fa8 100644
--- a/source/fitz/unzip.c
+++ b/source/fitz/unzip.c
@@ -230,7 +230,7 @@ static void ensure_zip_entries(fz_context *ctx, fz_zip_archive *zip)
size_t size, back, maxback;
size_t i, n;
- fz_seek(ctx, file, 0, FZ_SEEK_END);
+ fz_seek(ctx, file, 0, SEEK_END);
size = fz_tell(ctx, file);
maxback = fz_minz(size, 0xFFFF + sizeof buf);
@@ -238,7 +238,7 @@ static void ensure_zip_entries(fz_context *ctx, fz_zip_archive *zip)
while (back < maxback)
{
- fz_seek(ctx, file, (fz_off_t)(size - back), 0);
+ fz_seek(ctx, file, (int64_t)(size - back), 0);
n = fz_read(ctx, file, buf, sizeof buf);
if (n < 4)
break;
diff --git a/source/fitz/xml.c b/source/fitz/xml.c
index bcd3179c..06583952 100644
--- a/source/fitz/xml.c
+++ b/source/fitz/xml.c
@@ -88,6 +88,7 @@ struct fz_xml_s
fz_xml *up, *down, *tail, *prev, *next;
};
+#if 0
static void xml_indent(int n)
{
while (n--) {
@@ -144,6 +145,7 @@ void fz_debug_xml(fz_xml *item, int level)
printf(")%s\n", item->name);
}
}
+#endif
fz_xml *fz_xml_prev(fz_xml *item)
{
diff --git a/source/fitz/zip.c b/source/fitz/zip.c
index 45ce4488..fbca0590 100644
--- a/source/fitz/zip.c
+++ b/source/fitz/zip.c
@@ -69,7 +69,7 @@ fz_write_zip_entry(fz_context *ctx, fz_zip_writer *zip, const char *name, fz_buf
void
fz_close_zip_writer(fz_context *ctx, fz_zip_writer *zip)
{
- fz_off_t offset = fz_tell_output(ctx, zip->output);
+ int64_t offset = fz_tell_output(ctx, zip->output);
fz_write_data(ctx, zip->output, zip->central->data, zip->central->len);
diff --git a/source/gprf/gprf-doc.c b/source/gprf/gprf-doc.c
index 0b80223c..44e5d817 100644
--- a/source/gprf/gprf-doc.c
+++ b/source/gprf/gprf-doc.c
@@ -123,7 +123,7 @@ struct gprf_page_s
typedef struct fz_image_gprf_s
{
fz_image super;
- fz_off_t offset[FZ_MAX_SEPARATIONS+3+1]; /* + RGB + END */
+ int64_t offset[FZ_MAX_SEPARATIONS+3+1]; /* + RGB + END */
gprf_file *file;
fz_separations *separations;
} fz_image_gprf;
@@ -476,7 +476,7 @@ gprf_get_pixmap(fz_context *ctx, fz_image *image_, fz_irect *area, int w, int h,
}
static fz_image *
-fz_new_gprf_image(fz_context *ctx, gprf_page *page, int imagenum, fz_off_t offsets[], fz_off_t end)
+fz_new_gprf_image(fz_context *ctx, gprf_page *page, int imagenum, int64_t offsets[], int64_t end)
{
fz_image_gprf *image = fz_malloc_struct(ctx, fz_image_gprf);
int tile_x = imagenum % page->tile_width;
@@ -509,7 +509,7 @@ fz_new_gprf_image(fz_context *ctx, gprf_page *page, int imagenum, fz_off_t offse
image->super.yres = page->doc->res;
image->super.mask = NULL;
image->file = fz_keep_gprf_file(ctx, page->file);
- memcpy(image->offset, offsets, sizeof(fz_off_t) * (3+seps));
+ memcpy(image->offset, offsets, sizeof(int64_t) * (3+seps));
image->offset[seps+3] = end;
image->separations = fz_keep_separations(ctx, page->separations);
@@ -762,7 +762,7 @@ read_tiles(fz_context *ctx, gprf_page *page)
}
/* Seek to the image data */
- fz_seek(ctx, file, (fz_off_t)offset, SEEK_SET);
+ fz_seek(ctx, file, (int64_t)offset, SEEK_SET);
num_tiles = page->tile_width * page->tile_height;
page->tiles = fz_calloc(ctx, num_tiles, sizeof(fz_image *));
@@ -773,16 +773,16 @@ read_tiles(fz_context *ctx, gprf_page *page)
{
for (x = 0; x < page->tile_width; x++)
{
- fz_off_t offsets[FZ_MAX_SEPARATIONS + 3]; /* SEPARATIONS + RGB */
+ int64_t offsets[FZ_MAX_SEPARATIONS + 3]; /* SEPARATIONS + RGB */
int j;
for (j = 0; j < num_seps+3; j++)
{
- offsets[j] = (fz_off_t)off;
+ offsets[j] = (int64_t)off;
off = fz_read_int64_le(ctx, file);
}
- page->tiles[i] = fz_new_gprf_image(ctx, page, i, offsets, (fz_off_t)off);
+ page->tiles[i] = fz_new_gprf_image(ctx, page, i, offsets, (int64_t)off);
i++;
}
}
diff --git a/source/gprf/gprf-skeleton.c b/source/gprf/gprf-skeleton.c
index 1c9ec146..d4ad734c 100644
--- a/source/gprf/gprf-skeleton.c
+++ b/source/gprf/gprf-skeleton.c
@@ -1,5 +1,7 @@
#include "mupdf/fitz.h"
+#include <string.h>
+
void
fz_save_gproof(fz_context *ctx, const char *pdf_file, fz_document *doc, const char *filename, int res,
const char *print_profile, const char *display_profile)
diff --git a/source/helpers/mu-office-lib/mu-office-lib.c b/source/helpers/mu-office-lib/mu-office-lib.c
index dc5be7e4..2e69d448 100644
--- a/source/helpers/mu-office-lib/mu-office-lib.c
+++ b/source/helpers/mu-office-lib/mu-office-lib.c
@@ -13,6 +13,8 @@
#include "mupdf/helpers/mu-threads.h"
#include "mupdf/memento.h"
+#include <assert.h>
+
enum
{
MuError_OK = 0,
diff --git a/source/pdf/pdf-graft.c b/source/pdf/pdf-graft.c
index c3d1e116..50454e40 100644
--- a/source/pdf/pdf-graft.c
+++ b/source/pdf/pdf-graft.c
@@ -1,6 +1,8 @@
#include "mupdf/fitz.h"
#include "mupdf/pdf.h"
+#include <assert.h>
+
struct pdf_graft_map_s
{
int refs;
diff --git a/source/pdf/pdf-interpret.c b/source/pdf/pdf-interpret.c
index acebdf87..528f9c90 100644
--- a/source/pdf/pdf-interpret.c
+++ b/source/pdf/pdf-interpret.c
@@ -852,7 +852,7 @@ pdf_process_stream(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, fz_stream
pdf_array_push_drop(ctx, csi->obj, pdf_new_real(ctx, doc, buf->f));
break;
case PDF_TOK_INT:
- pdf_array_push_drop(ctx, csi->obj, pdf_new_int_offset(ctx, doc, buf->i));
+ pdf_array_push_drop(ctx, csi->obj, pdf_new_int(ctx, doc, buf->i));
break;
case PDF_TOK_STRING:
pdf_array_push_drop(ctx, csi->obj, pdf_new_string(ctx, doc, buf->scratch, buf->len));
diff --git a/source/pdf/pdf-lex.c b/source/pdf/pdf-lex.c
index 2a1b4685..44c68557 100644
--- a/source/pdf/pdf-lex.c
+++ b/source/pdf/pdf-lex.c
@@ -645,7 +645,7 @@ void pdf_append_token(fz_context *ctx, fz_buffer *fzbuf, int tok, pdf_lexbuf *bu
fz_append_byte(ctx, fzbuf, '}');
break;
case PDF_TOK_INT:
- fz_append_printf(ctx, fzbuf, "%d", buf->i);
+ fz_append_printf(ctx, fzbuf, "%ld", buf->i);
break;
case PDF_TOK_REAL:
fz_append_printf(ctx, fzbuf, "%g", buf->f);
diff --git a/source/pdf/pdf-object.c b/source/pdf/pdf-object.c
index def683d0..7788869e 100644
--- a/source/pdf/pdf-object.c
+++ b/source/pdf/pdf-object.c
@@ -45,7 +45,7 @@ typedef struct pdf_obj_num_s
pdf_obj super;
union
{
- fz_off_t i;
+ int64_t i;
float f;
} u;
} pdf_obj_num;
@@ -111,7 +111,7 @@ pdf_new_bool(fz_context *ctx, pdf_document *doc, int b)
}
pdf_obj *
-pdf_new_int(fz_context *ctx, pdf_document *doc, int i)
+pdf_new_int(fz_context *ctx, pdf_document *doc, int64_t i)
{
pdf_obj_num *obj;
obj = Memento_label(fz_malloc(ctx, sizeof(pdf_obj_num)), "pdf_obj(int)");
@@ -123,18 +123,6 @@ pdf_new_int(fz_context *ctx, pdf_document *doc, int i)
}
pdf_obj *
-pdf_new_int_offset(fz_context *ctx, pdf_document *doc, fz_off_t i)
-{
- pdf_obj_num *obj;
- obj = Memento_label(fz_malloc(ctx, sizeof(pdf_obj_num)), "pdf_obj(offset)");
- obj->super.refs = 1;
- obj->super.kind = PDF_INT;
- obj->super.flags = 0;
- obj->u.i = i;
- return &obj->super;
-}
-
-pdf_obj *
pdf_new_real(fz_context *ctx, pdf_document *doc, float f)
{
pdf_obj_num *obj;
@@ -315,7 +303,7 @@ int pdf_to_int(fz_context *ctx, pdf_obj *obj)
return 0;
}
-fz_off_t pdf_to_offset(fz_context *ctx, pdf_obj *obj)
+int64_t pdf_to_int64(fz_context *ctx, pdf_obj *obj)
{
RESOLVE(obj);
if (obj < PDF_OBJ__LIMIT)
@@ -323,7 +311,7 @@ fz_off_t pdf_to_offset(fz_context *ctx, pdf_obj *obj)
if (obj->kind == PDF_INT)
return NUM(obj)->u.i;
if (obj->kind == PDF_REAL)
- return (fz_off_t)(NUM(obj)->u.f + 0.5f); /* No roundf in MSVC */
+ return (NUM(obj)->u.f + 0.5f); /* No roundf in MSVC */
return 0;
}
@@ -365,14 +353,7 @@ int pdf_to_str_len(fz_context *ctx, pdf_obj *obj)
return STRING(obj)->len;
}
-void pdf_set_int(fz_context *ctx, pdf_obj *obj, int i)
-{
- if (!OBJ_IS_INT(obj))
- return;
- NUM(obj)->u.i = i;
-}
-
-void pdf_set_int_offset(fz_context *ctx, pdf_obj *obj, fz_off_t i)
+void pdf_set_int(fz_context *ctx, pdf_obj *obj, int64_t i)
{
if (!OBJ_IS_INT(obj))
return;
diff --git a/source/pdf/pdf-parse.c b/source/pdf/pdf-parse.c
index 7772bff2..797d4c56 100644
--- a/source/pdf/pdf-parse.c
+++ b/source/pdf/pdf-parse.c
@@ -322,7 +322,7 @@ pdf_parse_array(fz_context *ctx, pdf_document *doc, fz_stream *file, pdf_lexbuf
{
pdf_obj *ary = NULL;
pdf_obj *obj = NULL;
- fz_off_t a = 0, b = 0, n = 0;
+ int64_t a = 0, b = 0, n = 0;
pdf_token tok;
pdf_obj *op = NULL;
@@ -340,12 +340,12 @@ pdf_parse_array(fz_context *ctx, pdf_document *doc, fz_stream *file, pdf_lexbuf
{
if (n > 0)
{
- obj = pdf_new_int_offset(ctx, doc, a);
+ obj = pdf_new_int(ctx, doc, a);
pdf_array_push_drop(ctx, ary, obj);
}
if (n > 1)
{
- obj = pdf_new_int_offset(ctx, doc, b);
+ obj = pdf_new_int(ctx, doc, b);
pdf_array_push_drop(ctx, ary, obj);
}
n = 0;
@@ -353,7 +353,7 @@ pdf_parse_array(fz_context *ctx, pdf_document *doc, fz_stream *file, pdf_lexbuf
if (tok == PDF_TOK_INT && n == 2)
{
- obj = pdf_new_int_offset(ctx, doc, a);
+ obj = pdf_new_int(ctx, doc, a);
pdf_array_push_drop(ctx, ary, obj);
a = b;
n --;
@@ -438,7 +438,7 @@ pdf_parse_dict(fz_context *ctx, pdf_document *doc, fz_stream *file, pdf_lexbuf *
pdf_obj *key = NULL;
pdf_obj *val = NULL;
pdf_token tok;
- fz_off_t a, b;
+ int64_t a, b;
dict = pdf_new_dict(ctx, doc, 8);
@@ -489,7 +489,7 @@ pdf_parse_dict(fz_context *ctx, pdf_document *doc, fz_stream *file, pdf_lexbuf *
if (tok == PDF_TOK_CLOSE_DICT || tok == PDF_TOK_NAME ||
(tok == PDF_TOK_KEYWORD && !strcmp(buf->scratch, "ID")))
{
- val = pdf_new_int_offset(ctx, doc, a);
+ val = pdf_new_int(ctx, doc, a);
pdf_dict_put(ctx, dict, key, val);
pdf_drop_obj(ctx, val);
val = NULL;
@@ -549,7 +549,7 @@ pdf_parse_stm_obj(fz_context *ctx, pdf_document *doc, fz_stream *file, pdf_lexbu
case PDF_TOK_TRUE: return pdf_new_bool(ctx, doc, 1); break;
case PDF_TOK_FALSE: return pdf_new_bool(ctx, doc, 0); break;
case PDF_TOK_NULL: return pdf_new_null(ctx, doc); break;
- case PDF_TOK_INT: return pdf_new_int_offset(ctx, doc, buf->i); break;
+ case PDF_TOK_INT: return pdf_new_int(ctx, doc, buf->i); break;
default: fz_throw(ctx, FZ_ERROR_SYNTAX, "unknown token in object stream");
}
}
@@ -557,13 +557,13 @@ pdf_parse_stm_obj(fz_context *ctx, pdf_document *doc, fz_stream *file, pdf_lexbu
pdf_obj *
pdf_parse_ind_obj(fz_context *ctx, pdf_document *doc,
fz_stream *file, pdf_lexbuf *buf,
- int *onum, int *ogen, fz_off_t *ostmofs, int *try_repair)
+ int *onum, int *ogen, int64_t *ostmofs, int *try_repair)
{
pdf_obj *obj = NULL;
int num = 0, gen = 0;
- fz_off_t stm_ofs;
+ int64_t stm_ofs;
pdf_token tok;
- fz_off_t a, b;
+ int64_t a, b;
int read_next_token = 1;
fz_var(obj);
@@ -619,7 +619,7 @@ pdf_parse_ind_obj(fz_context *ctx, pdf_document *doc,
if (tok == PDF_TOK_STREAM || tok == PDF_TOK_ENDOBJ)
{
- obj = pdf_new_int_offset(ctx, doc, a);
+ obj = pdf_new_int(ctx, doc, a);
read_next_token = 0;
break;
}
diff --git a/source/pdf/pdf-pkcs7.c b/source/pdf/pdf-pkcs7.c
index 26db7909..735548d0 100644
--- a/source/pdf/pdf-pkcs7.c
+++ b/source/pdf/pdf-pkcs7.c
@@ -689,11 +689,11 @@ void pdf_write_digest(fz_context *ctx, pdf_document *doc, const char *filename,
if (p7_len*2 + 2 > digest_length)
fz_throw(ctx, FZ_ERROR_GENERIC, "Insufficient space for digest");
- f = fz_fopen(filename, "rb+");
+ f = fopen(filename, "rb+");
if (f == NULL)
fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to write digest");
- fz_fseek(f, digest_offset+1, SEEK_SET);
+ fseek(f, digest_offset+1, SEEK_SET);
for (i = 0; i < p7_len; i++)
fprintf(f, "%02x", p7_ptr[i]);
diff --git a/source/pdf/pdf-repair.c b/source/pdf/pdf-repair.c
index e4606c27..ca149bd3 100644
--- a/source/pdf/pdf-repair.c
+++ b/source/pdf/pdf-repair.c
@@ -32,7 +32,7 @@ static void add_root(fz_context *ctx, pdf_obj *obj, pdf_obj ***roots, int *num_r
}
int
-pdf_repair_obj(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf, fz_off_t *stmofsp, int *stmlenp, pdf_obj **encrypt, pdf_obj **id, pdf_obj **page, fz_off_t *tmpofs, pdf_obj **root)
+pdf_repair_obj(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf, int64_t *stmofsp, int *stmlenp, pdf_obj **encrypt, pdf_obj **id, pdf_obj **page, int64_t *tmpofs, pdf_obj **root)
{
fz_stream *file = doc->file;
pdf_token tok;
@@ -308,7 +308,7 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc)
int num = 0;
int gen = 0;
- fz_off_t tmpofs, stm_ofs, numofs = 0, genofs = 0;
+ int64_t tmpofs, stm_ofs, numofs = 0, genofs = 0;
int stm_len;
pdf_token tok;
int next;
@@ -358,7 +358,7 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc)
{
if (memcmp(&buf->scratch[j], "%PDF", 4) == 0)
{
- fz_seek(ctx, doc->file, (fz_off_t)(j + 8), 0); /* skip "%PDF-X.Y" */
+ fz_seek(ctx, doc->file, (int64_t)(j + 8), 0); /* skip "%PDF-X.Y" */
break;
}
}
diff --git a/source/pdf/pdf-stream.c b/source/pdf/pdf-stream.c
index c7bf5285..c89da5c4 100644
--- a/source/pdf/pdf-stream.c
+++ b/source/pdf/pdf-stream.c
@@ -280,7 +280,7 @@ build_filter_chain(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_obj
* orig_num and orig_gen are used purely to seed the encryption.
*/
static fz_stream *
-pdf_open_raw_filter(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_obj *stmobj, int num, int *orig_num, int *orig_gen, fz_off_t offset)
+pdf_open_raw_filter(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_obj *stmobj, int num, int *orig_num, int *orig_gen, int64_t offset)
{
pdf_xref_entry *x = NULL;
fz_stream *chain2;
@@ -336,7 +336,7 @@ pdf_open_raw_filter(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_ob
* to stream length and decrypting.
*/
static fz_stream *
-pdf_open_filter(fz_context *ctx, pdf_document *doc, fz_stream *chain, pdf_obj *stmobj, int num, fz_off_t offset, fz_compression_params *imparams)
+pdf_open_filter(fz_context *ctx, pdf_document *doc, fz_stream *chain, pdf_obj *stmobj, int num, int64_t offset, fz_compression_params *imparams)
{
pdf_obj *filters;
pdf_obj *params;
@@ -382,7 +382,7 @@ pdf_open_inline_stream(fz_context *ctx, pdf_document *doc, pdf_obj *stmobj, int
{
pdf_obj *filters;
pdf_obj *params;
- fz_off_t offset;
+ int64_t offset;
filters = pdf_dict_geta(ctx, stmobj, PDF_NAME_Filter, PDF_NAME_F);
params = pdf_dict_geta(ctx, stmobj, PDF_NAME_DecodeParms, PDF_NAME_DP);
@@ -479,7 +479,7 @@ pdf_open_stream_number(fz_context *ctx, pdf_document *doc, int num)
}
fz_stream *
-pdf_open_stream_with_offset(fz_context *ctx, pdf_document *doc, int num, pdf_obj *dict, fz_off_t stm_ofs)
+pdf_open_stream_with_offset(fz_context *ctx, pdf_document *doc, int num, pdf_obj *dict, int64_t stm_ofs)
{
if (stm_ofs == 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "object is not a stream");
diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c
index 164df6b4..9f123206 100644
--- a/source/pdf/pdf-write.c
+++ b/source/pdf/pdf-write.c
@@ -67,7 +67,7 @@ struct pdf_write_state_s
int do_clean;
int *use_list;
- fz_off_t *ofs_list;
+ int64_t *ofs_list;
int *gen_list;
int *renumber_map;
int continue_on_error;
@@ -75,10 +75,10 @@ struct pdf_write_state_s
/* The following extras are required for linearization */
int *rev_renumber_map;
int start;
- fz_off_t first_xref_offset;
- fz_off_t main_xref_offset;
- fz_off_t first_xref_entry_offset;
- fz_off_t file_len;
+ int64_t first_xref_offset;
+ int64_t main_xref_offset;
+ int64_t first_xref_entry_offset;
+ int64_t file_len;
int hints_shared_offset;
int hintstream_len;
pdf_obj *linear_l;
@@ -1460,13 +1460,13 @@ linearize(fz_context *ctx, pdf_document *doc, pdf_write_state *opts)
static void
update_linearization_params(fz_context *ctx, pdf_document *doc, pdf_write_state *opts)
{
- fz_off_t offset;
+ int64_t offset;
pdf_set_int(ctx, opts->linear_l, opts->file_len);
/* Primary hint stream offset (of object, not stream!) */
- pdf_set_int_offset(ctx, opts->linear_h0, opts->ofs_list[pdf_xref_len(ctx, doc)-1]);
+ pdf_set_int(ctx, opts->linear_h0, opts->ofs_list[pdf_xref_len(ctx, doc)-1]);
/* Primary hint stream length (of object, not stream!) */
offset = (opts->start == 1 ? opts->main_xref_offset : opts->ofs_list[1] + opts->hintstream_len);
- pdf_set_int_offset(ctx, opts->linear_h1, offset - opts->ofs_list[pdf_xref_len(ctx, doc)-1]);
+ pdf_set_int(ctx, opts->linear_h1, offset - opts->ofs_list[pdf_xref_len(ctx, doc)-1]);
/* Object number of first pages page object (the first object of page 0) */
pdf_set_int(ctx, opts->linear_o, opts->page_object_lists->page[0]->object[0]);
/* Offset of end of first page (first page is followed by primary
@@ -1474,13 +1474,13 @@ update_linearization_params(fz_context *ctx, pdf_document *doc, pdf_write_state
* primary hint stream counts as part of the first pages data, I think.
*/
offset = (opts->start == 1 ? opts->main_xref_offset : opts->ofs_list[1] + opts->hintstream_len);
- pdf_set_int_offset(ctx, opts->linear_e, offset);
+ pdf_set_int(ctx, opts->linear_e, offset);
/* Number of pages in document */
pdf_set_int(ctx, opts->linear_n, opts->page_count);
/* Offset of first entry in main xref table */
- pdf_set_int_offset(ctx, opts->linear_t, opts->first_xref_entry_offset + opts->hintstream_len);
+ pdf_set_int(ctx, opts->linear_t, opts->first_xref_entry_offset + opts->hintstream_len);
/* Offset of shared objects hint table in the primary hint stream */
- pdf_set_int_offset(ctx, opts->hints_s, opts->hints_shared_offset);
+ pdf_set_int(ctx, opts->hints_s, opts->hints_shared_offset);
/* Primary hint stream length */
pdf_set_int(ctx, opts->hints_length, opts->hintstream_len);
}
@@ -1918,13 +1918,13 @@ static void writexrefsubsect(fz_context *ctx, pdf_write_state *opts, int from, i
for (num = from; num < to; num++)
{
if (opts->use_list[num])
- fz_write_printf(ctx, opts->out, "%010Zd %05d n \n", opts->ofs_list[num], opts->gen_list[num]);
+ fz_write_printf(ctx, opts->out, "%010ld %05d n \n", opts->ofs_list[num], opts->gen_list[num]);
else
- fz_write_printf(ctx, opts->out, "%010Zd %05d f \n", opts->ofs_list[num], opts->gen_list[num]);
+ fz_write_printf(ctx, opts->out, "%010ld %05d f \n", opts->ofs_list[num], opts->gen_list[num]);
}
}
-static void writexref(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, int from, int to, int first, int main_xref_offset, int startxref)
+static void writexref(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, int from, int to, int first, int64_t main_xref_offset, int64_t startxref)
{
pdf_obj *trailer = NULL;
pdf_obj *obj;
@@ -2003,7 +2003,7 @@ static void writexref(fz_context *ctx, pdf_document *doc, pdf_write_state *opts,
pdf_drop_obj(ctx, trailer);
- fz_write_printf(ctx, opts->out, "startxref\n%d\n%%%%EOF\n", startxref);
+ fz_write_printf(ctx, opts->out, "startxref\n%ld\n%%%%EOF\n", startxref);
doc->has_xref_streams = 0;
}
@@ -2025,7 +2025,7 @@ static void writexrefstreamsubsect(fz_context *ctx, pdf_document *doc, pdf_write
}
}
-static void writexrefstream(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, int from, int to, int first, int main_xref_offset, int startxref)
+static void writexrefstream(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, int from, int to, int first, int64_t main_xref_offset, int64_t startxref)
{
int num;
pdf_obj *dict = NULL;
@@ -2127,7 +2127,7 @@ static void writexrefstream(fz_context *ctx, pdf_document *doc, pdf_write_state
pdf_update_stream(ctx, doc, dict, fzbuf, 0);
writeobject(ctx, doc, opts, num, 0, 0);
- fz_write_printf(ctx, opts->out, "startxref\n%Zd\n%%%%EOF\n", startxref);
+ fz_write_printf(ctx, opts->out, "startxref\n%ld\n%%%%EOF\n", startxref);
}
fz_always(ctx)
{
@@ -2142,9 +2142,9 @@ static void writexrefstream(fz_context *ctx, pdf_document *doc, pdf_write_state
}
static void
-padto(fz_context *ctx, fz_output *out, fz_off_t target)
+padto(fz_context *ctx, fz_output *out, int64_t target)
{
- fz_off_t pos = fz_tell_output(ctx, out);
+ int64_t pos = fz_tell_output(ctx, out);
assert(pos <= target);
while (pos < target)
@@ -2218,7 +2218,7 @@ writeobjects(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, int pass
dowriteobject(ctx, doc, opts, num, pass);
if (opts->do_linear && pass == 1)
{
- fz_off_t offset = (opts->start == 1 ? opts->main_xref_offset : opts->ofs_list[1] + opts->hintstream_len);
+ int64_t offset = (opts->start == 1 ? opts->main_xref_offset : opts->ofs_list[1] + opts->hintstream_len);
padto(ctx, opts->out, offset);
}
for (num = 1; num < opts->start; num++)
@@ -2479,7 +2479,7 @@ make_page_offset_hints(fz_context *ctx, pdf_document *doc, pdf_write_state *opts
for (j = 0; j < pop[0]->len; j++)
{
int o = pop[0]->object[j];
- fz_off_t min, max;
+ int64_t min, max;
min = opts->ofs_list[o];
if (o == opts->start-1)
max = opts->main_xref_offset;
@@ -2601,7 +2601,7 @@ static void complete_signatures(fz_context *ctx, pdf_document *doc, pdf_write_st
{
pdf_obj *byte_range;
- f = fz_fopen(filename, "rb+");
+ f = fopen(filename, "rb+");
if (!f)
fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to open %s to complete signatures", filename);
@@ -2610,7 +2610,7 @@ static void complete_signatures(fz_context *ctx, pdf_document *doc, pdf_write_st
{
char *bstr, *cstr, *fstr;
int pnum = pdf_obj_parent_num(ctx, pdf_dict_getl(ctx, usig->field, PDF_NAME_V, PDF_NAME_ByteRange, NULL));
- fz_fseek(f, opts->ofs_list[pnum], SEEK_SET);
+ fseek(f, opts->ofs_list[pnum], SEEK_SET);
(void)fread(buf, 1, sizeof(buf), f);
buf[sizeof(buf)-1] = 0;
@@ -2653,7 +2653,7 @@ static void complete_signatures(fz_context *ctx, pdf_document *doc, pdf_write_st
/* Write the byte range to the file */
for (usig = xref->unsaved_sigs; usig; usig = usig->next)
{
- fz_fseek(f, usig->byte_range_start, SEEK_SET);
+ fseek(f, usig->byte_range_start, SEEK_SET);
fwrite(buf, 1, usig->byte_range_end - usig->byte_range_start, f);
}
@@ -2720,7 +2720,7 @@ static void initialise_write_state(fz_context *ctx, pdf_document *doc, const pdf
* 1 to n access rather than 0..n-1, and add space for 2 new
* extra entries that may be required for linearization. */
opts->use_list = fz_malloc_array(ctx, xref_len + 3, sizeof(int));
- opts->ofs_list = fz_malloc_array(ctx, xref_len + 3, sizeof(fz_off_t));
+ opts->ofs_list = fz_malloc_array(ctx, xref_len + 3, sizeof(int64_t));
opts->gen_list = fz_calloc(ctx, xref_len + 3, sizeof(int));
opts->renumber_map = fz_malloc_array(ctx, xref_len + 3, sizeof(int));
opts->rev_renumber_map = fz_malloc_array(ctx, xref_len + 3, sizeof(int));
diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c
index 92ccf34e..ba2d575f 100644
--- a/source/pdf/pdf-xref.c
+++ b/source/pdf/pdf-xref.c
@@ -6,6 +6,12 @@
#include <limits.h>
#include <string.h>
+#ifdef _MSC_VER
+#ifndef INT64_MAX
+#define INT64_MAX 9223372036854775807i64
+#endif
+#endif
+
#undef DEBUG_PROGESSIVE_ADVANCE
#ifdef DEBUG_PROGESSIVE_ADVANCE
@@ -588,7 +594,7 @@ pdf_load_version(fz_context *ctx, pdf_document *doc)
{
char buf[20];
- fz_seek(ctx, doc->file, 0, FZ_SEEK_SET);
+ fz_seek(ctx, doc->file, 0, SEEK_SET);
fz_read_line(ctx, doc->file, buf, sizeof buf);
if (memcmp(buf, "%PDF-", 5) != 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot recognize version marker");
@@ -604,14 +610,14 @@ pdf_read_start_xref(fz_context *ctx, pdf_document *doc)
{
unsigned char buf[1024];
size_t i, n;
- fz_off_t t;
+ int64_t t;
- fz_seek(ctx, doc->file, 0, FZ_SEEK_END);
+ fz_seek(ctx, doc->file, 0, SEEK_END);
doc->file_size = fz_tell(ctx, doc->file);
- t = fz_maxo(0, doc->file_size - (fz_off_t)sizeof buf);
- fz_seek(ctx, doc->file, t, FZ_SEEK_SET);
+ t = fz_maxi64(0, doc->file_size - (int64_t)sizeof buf);
+ fz_seek(ctx, doc->file, t, SEEK_SET);
n = fz_read(ctx, doc->file, buf, sizeof buf);
if (n < 9)
@@ -628,7 +634,7 @@ pdf_read_start_xref(fz_context *ctx, pdf_document *doc)
doc->startxref = 0;
while (i < n && buf[i] >= '0' && buf[i] <= '9')
{
- if (doc->startxref >= FZ_OFF_MAX/10)
+ if (doc->startxref >= INT64_MAX/10)
fz_throw(ctx, FZ_ERROR_GENERIC, "startxref too large");
doc->startxref = doc->startxref * 10 + (buf[i++] - '0');
}
@@ -673,13 +679,13 @@ static int fz_skip_string(fz_context *ctx, fz_stream *stm, const char *str)
static int
pdf_xref_size_from_old_trailer(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf)
{
- fz_off_t len;
+ int64_t len;
char *s;
- fz_off_t t;
+ int64_t t;
pdf_token tok;
int c;
int size = 0;
- fz_off_t ofs;
+ int64_t ofs;
pdf_obj *trailer = NULL;
size_t n;
@@ -704,13 +710,13 @@ pdf_xref_size_from_old_trailer(fz_context *ctx, pdf_document *doc, pdf_lexbuf *b
fz_strsep(&s, " "); /* ignore ofs */
if (!s)
fz_throw(ctx, FZ_ERROR_GENERIC, "invalid range marker in xref");
- len = fz_atoo(fz_strsep(&s, " "));
+ len = fz_atoi64(fz_strsep(&s, " "));
if (len < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "xref range marker must be positive");
/* broken pdfs where the section is not on a separate line */
if (s && *s != '\0')
- fz_seek(ctx, doc->file, -(2 + (int)strlen(s)), FZ_SEEK_CUR);
+ fz_seek(ctx, doc->file, -(2 + (int)strlen(s)), SEEK_CUR);
t = fz_tell(ctx, doc->file);
if (t < 0)
@@ -729,10 +735,10 @@ pdf_xref_size_from_old_trailer(fz_context *ctx, pdf_document *doc, pdf_lexbuf *b
else
n = 20;
- if (len > (fz_off_t)((FZ_OFF_MAX - t) / n))
+ if (len > (int64_t)((INT64_MAX - t) / n))
fz_throw(ctx, FZ_ERROR_GENERIC, "xref has too many entries");
- fz_seek(ctx, doc->file, (fz_off_t)(t + n * len), FZ_SEEK_SET);
+ fz_seek(ctx, doc->file, (int64_t)(t + n * len), SEEK_SET);
}
fz_try(ctx)
@@ -760,13 +766,13 @@ pdf_xref_size_from_old_trailer(fz_context *ctx, pdf_document *doc, pdf_lexbuf *b
fz_rethrow(ctx);
}
- fz_seek(ctx, doc->file, ofs, FZ_SEEK_SET);
+ fz_seek(ctx, doc->file, ofs, SEEK_SET);
return size;
}
static pdf_xref_entry *
-pdf_xref_find_subsection(fz_context *ctx, pdf_document *doc, fz_off_t ofs, int len)
+pdf_xref_find_subsection(fz_context *ctx, pdf_document *doc, int64_t ofs, int len)
{
pdf_xref *xref = &doc->xref_sections[doc->num_xref_sections-1];
pdf_xref_subsec *sub;
@@ -828,12 +834,12 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf)
{
fz_stream *file = doc->file;
- fz_off_t ofs;
+ int64_t ofs;
int len;
char *s;
size_t n;
pdf_token tok;
- fz_off_t i;
+ int64_t i;
int c;
int xref_len = pdf_xref_size_from_old_trailer(ctx, doc, buf);
pdf_xref_entry *table;
@@ -852,19 +858,19 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf)
fz_read_line(ctx, file, buf->scratch, buf->size);
s = buf->scratch;
- ofs = fz_atoo(fz_strsep(&s, " "));
+ ofs = fz_atoi64(fz_strsep(&s, " "));
len = fz_atoi(fz_strsep(&s, " "));
/* broken pdfs where the section is not on a separate line */
if (s && *s != '\0')
{
fz_warn(ctx, "broken xref section. proceeding anyway.");
- fz_seek(ctx, file, -(2 + (int)strlen(s)), FZ_SEEK_CUR);
+ fz_seek(ctx, file, -(2 + (int)strlen(s)), SEEK_CUR);
}
if (ofs < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "out of range object num in xref: %d", (int)ofs);
- if (ofs > FZ_OFF_MAX - len)
+ if (ofs > INT64_MAX - len)
fz_throw(ctx, FZ_ERROR_GENERIC, "xref section object numbers too big");
/* broken pdfs where size in trailer undershoots entries in xref sections */
@@ -894,7 +900,7 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf)
while (*s != '\0' && iswhite(*s))
s++;
- entry->ofs = fz_atoo(s);
+ entry->ofs = fz_atoi64(s);
entry->gen = fz_atoi(s + 11);
entry->num = (int)i;
entry->type = s[17];
@@ -922,7 +928,7 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf)
}
static void
-pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, fz_off_t i0, int i1, int w0, int w1, int w2)
+pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, int64_t i0, int i1, int w0, int w1, int w2)
{
pdf_xref_entry *table;
int i, n;
@@ -937,7 +943,7 @@ pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, fz
{
pdf_xref_entry *entry = &table[i-i0];
int a = 0;
- fz_off_t b = 0;
+ int64_t b = 0;
int c = 0;
if (fz_is_eof(ctx, stm))
@@ -972,7 +978,7 @@ pdf_read_new_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf)
pdf_obj *index = NULL;
pdf_obj *obj = NULL;
int gen, num = 0;
- fz_off_t ofs, stm_ofs;
+ int64_t ofs, stm_ofs;
int size, w0, w1, w2;
int t;
@@ -1059,12 +1065,12 @@ pdf_read_new_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf)
}
static pdf_obj *
-pdf_read_xref(fz_context *ctx, pdf_document *doc, fz_off_t ofs, pdf_lexbuf *buf)
+pdf_read_xref(fz_context *ctx, pdf_document *doc, int64_t ofs, pdf_lexbuf *buf)
{
pdf_obj *trailer;
int c;
- fz_seek(ctx, doc->file, ofs, FZ_SEEK_SET);
+ fz_seek(ctx, doc->file, ofs, SEEK_SET);
while (iswhite(fz_peek_byte(ctx, doc->file)))
fz_read_byte(ctx, doc->file);
@@ -1086,15 +1092,15 @@ struct ofs_list_s
{
int max;
int len;
- fz_off_t *list;
+ int64_t *list;
};
-static fz_off_t
-read_xref_section(fz_context *ctx, pdf_document *doc, fz_off_t ofs, pdf_lexbuf *buf, ofs_list *offsets)
+static int64_t
+read_xref_section(fz_context *ctx, pdf_document *doc, int64_t ofs, pdf_lexbuf *buf, ofs_list *offsets)
{
pdf_obj *trailer = NULL;
- fz_off_t xrefstmofs = 0;
- fz_off_t prevofs = 0;
+ int64_t xrefstmofs = 0;
+ int64_t prevofs = 0;
fz_var(trailer);
@@ -1125,7 +1131,7 @@ read_xref_section(fz_context *ctx, pdf_document *doc, fz_off_t ofs, pdf_lexbuf *
/* FIXME: do we overwrite free entries properly? */
/* FIXME: Does this work properly with progression? */
- xrefstmofs = pdf_to_offset(ctx, pdf_dict_get(ctx, trailer, PDF_NAME_XRefStm));
+ xrefstmofs = pdf_to_int64(ctx, pdf_dict_get(ctx, trailer, PDF_NAME_XRefStm));
if (xrefstmofs)
{
if (xrefstmofs < 0)
@@ -1139,8 +1145,7 @@ read_xref_section(fz_context *ctx, pdf_document *doc, fz_off_t ofs, pdf_lexbuf *
pdf_drop_obj(ctx, pdf_read_xref(ctx, doc, xrefstmofs, buf));
}
- /* FIXME: pdf_to_offset? */
- prevofs = pdf_to_offset(ctx, pdf_dict_get(ctx, trailer, PDF_NAME_Prev));
+ prevofs = pdf_to_int64(ctx, pdf_dict_get(ctx, trailer, PDF_NAME_Prev));
if (prevofs < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream offset for previous xref stream");
}
@@ -1157,7 +1162,7 @@ read_xref_section(fz_context *ctx, pdf_document *doc, fz_off_t ofs, pdf_lexbuf *
}
static void
-pdf_read_xref_sections(fz_context *ctx, pdf_document *doc, fz_off_t ofs, pdf_lexbuf *buf, int read_previous)
+pdf_read_xref_sections(fz_context *ctx, pdf_document *doc, int64_t ofs, pdf_lexbuf *buf, int read_previous)
{
ofs_list list;
@@ -1263,7 +1268,7 @@ pdf_load_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf)
/* Read this into a local variable here, because pdf_get_xref_entry
* may solidify the xref, hence invalidating "entry", meaning we
* need a stashed value for the throw. */
- fz_off_t ofs = entry->ofs;
+ int64_t ofs = entry->ofs;
if (ofs <= 0 || ofs >= xref_len || pdf_get_xref_entry(ctx, doc, ofs)->type != 'n')
fz_throw(ctx, FZ_ERROR_GENERIC, "invalid reference to an objstm that does not exist: %d (%d 0 R)", (int)ofs, i);
}
@@ -1277,7 +1282,7 @@ pdf_load_linear(fz_context *ctx, pdf_document *doc)
pdf_obj *hint = NULL;
pdf_obj *o;
int num, gen, lin, len;
- fz_off_t stmofs;
+ int64_t stmofs;
fz_var(dict);
fz_var(hint);
@@ -1573,10 +1578,10 @@ pdf_load_obj_stm(fz_context *ctx, pdf_document *doc, int num, pdf_lexbuf *buf, i
fz_stream *stm = NULL;
pdf_obj *objstm = NULL;
int *numbuf = NULL;
- fz_off_t *ofsbuf = NULL;
+ int64_t *ofsbuf = NULL;
pdf_obj *obj;
- fz_off_t first;
+ int64_t first;
int count;
int i;
pdf_token tok;
@@ -1616,13 +1621,13 @@ pdf_load_obj_stm(fz_context *ctx, pdf_document *doc, int num, pdf_lexbuf *buf, i
ofsbuf[i] = buf->i;
}
- fz_seek(ctx, stm, first, FZ_SEEK_SET);
+ fz_seek(ctx, stm, first, SEEK_SET);
for (i = 0; i < count; i++)
{
int xref_len = pdf_xref_len(ctx, doc);
pdf_xref_entry *entry;
- fz_seek(ctx, stm, first + ofsbuf[i], FZ_SEEK_SET);
+ fz_seek(ctx, stm, first + ofsbuf[i], SEEK_SET);
obj = pdf_parse_stm_obj(ctx, doc, stm, buf);
@@ -1683,16 +1688,16 @@ pdf_load_obj_stm(fz_context *ctx, pdf_document *doc, int num, pdf_lexbuf *buf, i
* object loading
*/
static int
-pdf_obj_read(fz_context *ctx, pdf_document *doc, fz_off_t *offset, int *nump, pdf_obj **page)
+pdf_obj_read(fz_context *ctx, pdf_document *doc, int64_t *offset, int *nump, pdf_obj **page)
{
pdf_lexbuf *buf = &doc->lexbuf.base;
int num, gen, tok;
- fz_off_t numofs, genofs, stmofs, tmpofs, newtmpofs;
+ int64_t numofs, genofs, stmofs, tmpofs, newtmpofs;
int xref_len;
pdf_xref_entry *entry;
numofs = *offset;
- fz_seek(ctx, doc->file, numofs, FZ_SEEK_SET);
+ fz_seek(ctx, doc->file, numofs, SEEK_SET);
/* We expect to read 'num' here */
tok = pdf_lex(ctx, doc->file, buf);
@@ -1847,7 +1852,7 @@ read_hinted_object(fz_context *ctx, pdf_document *doc, int num)
* there. */
int expected = num;
int curr_pos;
- fz_off_t start, offset;
+ int64_t start, offset;
while (doc->hint_obj_offsets[expected] == 0 && expected > 0)
expected--;
@@ -1898,7 +1903,7 @@ read_hinted_object(fz_context *ctx, pdf_document *doc, int num)
}
fz_always(ctx)
{
- fz_seek(ctx, doc->file, curr_pos, FZ_SEEK_SET);
+ fz_seek(ctx, doc->file, curr_pos, SEEK_SET);
}
fz_catch(ctx)
{
@@ -1937,7 +1942,7 @@ object_updated:
}
else if (x->type == 'n')
{
- fz_seek(ctx, doc->file, x->ofs, FZ_SEEK_SET);
+ fz_seek(ctx, doc->file, x->ofs, SEEK_SET);
fz_try(ctx)
{
@@ -2398,7 +2403,7 @@ pdf_load_hints(fz_context *ctx, pdf_document *doc, int objnum)
}
/* Skip items 5,6,7 as we don't use them */
- fz_seek(ctx, stream, shared_hint_offset, FZ_SEEK_SET);
+ fz_seek(ctx, stream, shared_hint_offset, SEEK_SET);
/* Read the shared object hints table: Header first */
shared_obj_num = fz_read_bits(ctx, stream, 32);
@@ -2511,16 +2516,16 @@ static void
pdf_load_hint_object(fz_context *ctx, pdf_document *doc)
{
pdf_lexbuf *buf = &doc->lexbuf.base;
- fz_off_t curr_pos;
+ int64_t curr_pos;
curr_pos = fz_tell(ctx, doc->file);
- fz_seek(ctx, doc->file, doc->hint_object_offset, FZ_SEEK_SET);
+ fz_seek(ctx, doc->file, doc->hint_object_offset, SEEK_SET);
fz_try(ctx)
{
while (1)
{
pdf_obj *page = NULL;
- fz_off_t tmpofs;
+ int64_t tmpofs;
int num, tok;
tok = pdf_lex(ctx, doc->file, buf);
@@ -2540,7 +2545,7 @@ pdf_load_hint_object(fz_context *ctx, pdf_document *doc)
}
fz_always(ctx)
{
- fz_seek(ctx, doc->file, curr_pos, FZ_SEEK_SET);
+ fz_seek(ctx, doc->file, curr_pos, SEEK_SET);
}
fz_catch(ctx)
{
@@ -2601,7 +2606,7 @@ pdf_obj *pdf_progressive_advance(fz_context *ctx, pdf_document *doc, int pagenum
}
fz_always(ctx)
{
- fz_seek(ctx, doc->file, curr_pos, FZ_SEEK_SET);
+ fz_seek(ctx, doc->file, curr_pos, SEEK_SET);
}
fz_catch(ctx)
{
diff --git a/source/svg/svg-run.c b/source/svg/svg-run.c
index 5302c640..4b7724f6 100644
--- a/source/svg/svg-run.c
+++ b/source/svg/svg-run.c
@@ -1109,8 +1109,7 @@ svg_run_element(fz_context *ctx, fz_device *dev, svg_document *doc, fz_xml *root
else
{
- /* debug print unrecognized tags */
- fz_debug_xml(root, 0);
+ /* ignore unrecognized tags */
}
}
diff --git a/source/tools/mjsgen.c b/source/tools/mjsgen.c
index cbe75c0d..04c0a435 100644
--- a/source/tools/mjsgen.c
+++ b/source/tools/mjsgen.c
@@ -5,6 +5,10 @@
#include "mupdf/fitz.h"
#include "mupdf/pdf.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
/*
A useful bit of bash script to call this to generate mjs files:
for f in tests_private/pdf/forms/v1.3/ *.pdf ; do g=${f%.*} ; echo $g ; ./mjsgen $g.pdf $g.mjs ; done
diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c
index f7b87626..c9c7bb55 100644
--- a/source/tools/mudraw.c
+++ b/source/tools/mudraw.c
@@ -2022,9 +2022,9 @@ int mudraw_main(int argc, char **argv)
if (showmemory)
{
- fprintf(stderr, "Total memory use = " FZ_FMT_zu " bytes\n", info.total);
- fprintf(stderr, "Peak memory use = " FZ_FMT_zu " bytes\n", info.peak);
- fprintf(stderr, "Current memory use = " FZ_FMT_zu " bytes\n", info.current);
+ char buf[100];
+ fz_snprintf(buf, sizeof buf, "Memory use total=%zu peak=%zu current=%zu", info.total, info.peak, info.current);
+ fprintf(stderr, "%s\n", buf);
}
return (errored != 0);
diff --git a/source/tools/muraster.c b/source/tools/muraster.c
index 6e65f7b2..e48b8b09 100644
--- a/source/tools/muraster.c
+++ b/source/tools/muraster.c
@@ -1728,9 +1728,9 @@ int main(int argc, char **argv)
if (showmemory)
{
- fprintf(stderr, "Total memory use = " FZ_FMT_zu " bytes\n", info.total);
- fprintf(stderr, "Peak memory use = " FZ_FMT_zu " bytes\n", info.peak);
- fprintf(stderr, "Current memory use = " FZ_FMT_zu " bytes\n", info.current);
+ char buf[100];
+ fz_snprintf(buf, sizeof buf, "Memory use total=%zu peak=%zu current=%zu", info.total, info.peak, info.current);
+ fprintf(stderr, "%s\n", buf);
}
return (errored != 0);
diff --git a/source/tools/pdfextract.c b/source/tools/pdfextract.c
index 1ae71c4f..8c17a980 100644
--- a/source/tools/pdfextract.c
+++ b/source/tools/pdfextract.c
@@ -48,13 +48,13 @@ static void writepixmap(fz_context *ctx, fz_pixmap *pix, char *file, int dorgb)
if (pix->n - pix->alpha <= 3)
{
- snprintf(buf, sizeof(buf), "%s.png", file);
+ fz_snprintf(buf, sizeof(buf), "%s.png", file);
printf("extracting image %s\n", buf);
fz_save_pixmap_as_png(ctx, pix, buf);
}
else
{
- snprintf(buf, sizeof(buf), "%s.pam", file);
+ fz_snprintf(buf, sizeof(buf), "%s.pam", file);
printf("extracting image %s\n", buf);
fz_save_pixmap_as_pam(ctx, pix, buf);
}
diff --git a/source/tools/pdfportfolio.c b/source/tools/pdfportfolio.c
index 056bb678..9a0efc01 100644
--- a/source/tools/pdfportfolio.c
+++ b/source/tools/pdfportfolio.c
@@ -6,6 +6,7 @@
#include "mupdf/pdf.h"
#include <stdlib.h>
+#include <string.h>
#include <stdio.h>
static pdf_document *doc = NULL;
diff --git a/source/xps/xps-imp.h b/source/xps/xps-imp.h
index cac5494a..7eff5670 100644
--- a/source/xps/xps-imp.h
+++ b/source/xps/xps-imp.h
@@ -183,7 +183,7 @@ typedef struct xps_entry_s xps_entry;
struct xps_entry_s
{
char *name;
- fz_off_t offset;
+ int64_t offset;
int csize;
int usize;
};