summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-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
52 files changed, 328 insertions, 264 deletions
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;
};