Commit 81e8752362eeab80f156eb74d1b523eba20a0366

Authored by Jay Berkenbilt
1 parent c833295a

Use qpdf_offset_t in place of off_t in public APIs.

off_t is used internally only when needed to talk to standard
libraries.  This requires that the "long long" type be supported by
the compiler.
ChangeLog
1 1 2012-06-21 Jay Berkenbilt <ejb@ql.org>
2 2  
  3 + * Instead of using off_t in the public APIs, use qpdf_offset_t
  4 + instead. This is defined as long long in qpdf/Types.h. If your
  5 + system doesn't support long long, you can redefine it.
  6 +
3 7 * Add pkg-config files
4 8  
5 9 * QPDFObjectHandle: add shallowCopy() method
... ...
configure.ac
... ... @@ -11,6 +11,7 @@ AC_CONFIG_FILES([libqpdf.pc])
11 11 AC_CONFIG_HEADERS([libqpdf/qpdf/qpdf-config.h])
12 12  
13 13 AC_PROG_CC
  14 +AC_PROG_CC_C99
14 15 AC_PROG_CXX
15 16 AC_HEADER_STDC
16 17 LT_INIT([win32-dll])
... ...
include/qpdf/Pl_Count.hh
... ... @@ -27,14 +27,14 @@ class Pl_Count: public Pipeline
27 27 virtual void finish();
28 28 // Returns the number of bytes written
29 29 QPDF_DLL
30   - off_t getCount() const;
  30 + qpdf_offset_t getCount() const;
31 31 // Returns the last character written, or '\0' if no characters
32 32 // have been written (in which case getCount() returns 0)
33 33 QPDF_DLL
34 34 unsigned char getLastChar() const;
35 35  
36 36 private:
37   - off_t count;
  37 + qpdf_offset_t count;
38 38 unsigned char last_char;
39 39 };
40 40  
... ...
include/qpdf/QPDF.hh
... ... @@ -394,7 +394,7 @@ class QPDF
394 394 friend class QPDF_Stream;
395 395 private:
396 396 static void pipeStreamData(QPDF* qpdf, int objid, int generation,
397   - off_t offset, size_t length,
  397 + qpdf_offset_t offset, size_t length,
398 398 QPDFObjectHandle dict,
399 399 Pipeline* pipeline)
400 400 {
... ... @@ -418,19 +418,19 @@ class QPDF
418 418 {
419 419 }
420 420  
421   - void setLastOffset(off_t);
422   - off_t getLastOffset() const;
  421 + void setLastOffset(qpdf_offset_t);
  422 + qpdf_offset_t getLastOffset() const;
423 423 std::string readLine();
424 424  
425 425 virtual std::string const& getName() const = 0;
426   - virtual off_t tell() = 0;
427   - virtual void seek(off_t offset, int whence) = 0;
  426 + virtual qpdf_offset_t tell() = 0;
  427 + virtual void seek(qpdf_offset_t offset, int whence) = 0;
428 428 virtual void rewind() = 0;
429 429 virtual size_t read(char* buffer, size_t length) = 0;
430 430 virtual void unreadCh(char ch) = 0;
431 431  
432 432 protected:
433   - off_t last_offset;
  433 + qpdf_offset_t last_offset;
434 434 };
435 435  
436 436 class FileInputSource: public InputSource
... ... @@ -441,8 +441,8 @@ class QPDF
441 441 void setFile(FILE* filep);
442 442 virtual ~FileInputSource();
443 443 virtual std::string const& getName() const;
444   - virtual off_t tell();
445   - virtual void seek(off_t offset, int whence);
  444 + virtual qpdf_offset_t tell();
  445 + virtual void seek(qpdf_offset_t offset, int whence);
446 446 virtual void rewind();
447 447 virtual size_t read(char* buffer, size_t length);
448 448 virtual void unreadCh(char ch);
... ... @@ -465,8 +465,8 @@ class QPDF
465 465 bool own_memory = false);
466 466 virtual ~BufferInputSource();
467 467 virtual std::string const& getName() const;
468   - virtual off_t tell();
469   - virtual void seek(off_t offset, int whence);
  468 + virtual qpdf_offset_t tell();
  469 + virtual void seek(qpdf_offset_t offset, int whence);
470 470 virtual void rewind();
471 471 virtual size_t read(char* buffer, size_t length);
472 472 virtual void unreadCh(char ch);
... ... @@ -475,7 +475,7 @@ class QPDF
475 475 bool own_memory;
476 476 std::string description;
477 477 Buffer* buf;
478   - off_t cur_offset;
  478 + qpdf_offset_t cur_offset;
479 479 };
480 480  
481 481 class ObjGen
... ... @@ -498,8 +498,8 @@ class QPDF
498 498 {
499 499 }
500 500 ObjCache(PointerHolder<QPDFObject> object,
501   - off_t end_before_space,
502   - off_t end_after_space) :
  501 + qpdf_offset_t end_before_space,
  502 + qpdf_offset_t end_after_space) :
503 503 object(object),
504 504 end_before_space(end_before_space),
505 505 end_after_space(end_after_space)
... ... @@ -507,18 +507,18 @@ class QPDF
507 507 }
508 508  
509 509 PointerHolder<QPDFObject> object;
510   - off_t end_before_space;
511   - off_t end_after_space;
  510 + qpdf_offset_t end_before_space;
  511 + qpdf_offset_t end_after_space;
512 512 };
513 513  
514 514 void parse(char const* password);
515 515 void warn(QPDFExc const& e);
516 516 void setTrailer(QPDFObjectHandle obj);
517   - void read_xref(off_t offset);
  517 + void read_xref(qpdf_offset_t offset);
518 518 void reconstruct_xref(QPDFExc& e);
519   - int read_xrefTable(off_t offset);
520   - int read_xrefStream(off_t offset);
521   - int processXRefStream(off_t offset, QPDFObjectHandle& xref_stream);
  519 + int read_xrefTable(qpdf_offset_t offset);
  520 + int read_xrefStream(qpdf_offset_t offset);
  521 + int processXRefStream(qpdf_offset_t offset, QPDFObjectHandle& xref_stream);
522 522 void insertXrefEntry(int obj, int f0, int f1, int f2,
523 523 bool overwrite = false);
524 524 void setLastObjectDescription(std::string const& description,
... ... @@ -532,12 +532,12 @@ class QPDF
532 532 bool in_array, bool in_dictionary);
533 533 size_t recoverStreamLength(
534 534 PointerHolder<InputSource> input, int objid, int generation,
535   - off_t stream_offset);
  535 + qpdf_offset_t stream_offset);
536 536 QPDFTokenizer::Token readToken(PointerHolder<InputSource>);
537 537  
538 538 QPDFObjectHandle readObjectAtOffset(
539 539 bool attempt_recovery,
540   - off_t offset, std::string const& description,
  540 + qpdf_offset_t offset, std::string const& description,
541 541 int exp_objid, int exp_generation,
542 542 int& act_objid, int& act_generation);
543 543 PointerHolder<QPDFObject> resolve(int objid, int generation);
... ... @@ -545,7 +545,7 @@ class QPDF
545 545  
546 546 // Calls finish() on the pipeline when done but does not delete it
547 547 void pipeStreamData(int objid, int generation,
548   - off_t offset, size_t length,
  548 + qpdf_offset_t offset, size_t length,
549 549 QPDFObjectHandle dict,
550 550 Pipeline* pipeline);
551 551  
... ... @@ -832,7 +832,8 @@ class QPDF
832 832 void readLinearizationData();
833 833 bool checkLinearizationInternal();
834 834 void dumpLinearizationDataInternal();
835   - QPDFObjectHandle readHintStream(Pipeline&, off_t offset, size_t length);
  835 + QPDFObjectHandle readHintStream(
  836 + Pipeline&, qpdf_offset_t offset, size_t length);
836 837 void readHPageOffset(BitStream);
837 838 void readHSharedObject(BitStream);
838 839 void readHGeneric(BitStream, HGeneric&);
... ...
include/qpdf/QPDFExc.hh
... ... @@ -21,7 +21,7 @@ class QPDFExc: public std::runtime_error
21 21 QPDFExc(qpdf_error_code_e error_code,
22 22 std::string const& filename,
23 23 std::string const& object,
24   - off_t offset,
  24 + qpdf_offset_t offset,
25 25 std::string const& message);
26 26 QPDF_DLL
27 27 virtual ~QPDFExc() throw ();
... ... @@ -43,20 +43,20 @@ class QPDFExc: public std::runtime_error
43 43 QPDF_DLL
44 44 std::string const& getObject() const;
45 45 QPDF_DLL
46   - off_t getFilePosition() const;
  46 + qpdf_offset_t getFilePosition() const;
47 47 QPDF_DLL
48 48 std::string const& getMessageDetail() const;
49 49  
50 50 private:
51 51 static std::string createWhat(std::string const& filename,
52 52 std::string const& object,
53   - off_t offset,
  53 + qpdf_offset_t offset,
54 54 std::string const& message);
55 55  
56 56 qpdf_error_code_e error_code;
57 57 std::string filename;
58 58 std::string object;
59   - off_t offset;
  59 + qpdf_offset_t offset;
60 60 std::string message;
61 61 };
62 62  
... ...
include/qpdf/QPDFObjectHandle.hh
... ... @@ -347,7 +347,7 @@ class QPDFObjectHandle
347 347 // object must be dictionary object
348 348 static QPDFObjectHandle newStream(
349 349 QPDF* qpdf, int objid, int generation,
350   - QPDFObjectHandle stream_dict, off_t offset, size_t length)
  350 + QPDFObjectHandle stream_dict, qpdf_offset_t offset, size_t length)
351 351 {
352 352 return QPDFObjectHandle::newStream(
353 353 qpdf, objid, generation, stream_dict, offset, length);
... ... @@ -395,7 +395,7 @@ class QPDFObjectHandle
395 395 static QPDFObjectHandle newIndirect(QPDF*, int objid, int generation);
396 396 static QPDFObjectHandle newStream(
397 397 QPDF* qpdf, int objid, int generation,
398   - QPDFObjectHandle stream_dict, off_t offset, size_t length);
  398 + QPDFObjectHandle stream_dict, qpdf_offset_t offset, size_t length);
399 399  
400 400 void assertInitialized() const;
401 401 void assertType(char const* type_name, bool istype);
... ...
include/qpdf/QPDFWriter.hh
... ... @@ -221,7 +221,8 @@ class QPDFWriter
221 221 void writePad(int nspaces);
222 222 void assignCompressedObjectNumbers(int objid);
223 223 void enqueueObject(QPDFObjectHandle object);
224   - void writeObjectStreamOffsets(std::vector<off_t>& offsets, int first_obj);
  224 + void writeObjectStreamOffsets(
  225 + std::vector<qpdf_offset_t>& offsets, int first_obj);
225 226 void writeObjectStream(QPDFObjectHandle object);
226 227 void writeObject(QPDFObjectHandle object, int object_stream_index = -1);
227 228 void writeTrailer(trailer_e which, int size,
... ... @@ -268,8 +269,8 @@ class QPDFWriter
268 269 int prev,
269 270 bool suppress_offsets,
270 271 int hint_id,
271   - off_t hint_offset,
272   - off_t hint_length);
  272 + qpdf_offset_t hint_offset,
  273 + qpdf_offset_t hint_length);
273 274 int writeXRefStream(int objid, int max_id, int max_offset,
274 275 trailer_e which, int first, int last, int size);
275 276 int writeXRefStream(int objid, int max_id, int max_offset,
... ... @@ -277,8 +278,8 @@ class QPDFWriter
277 278 // for linearization
278 279 int prev,
279 280 int hint_id,
280   - off_t hint_offset,
281   - off_t hint_length,
  281 + qpdf_offset_t hint_offset,
  282 + qpdf_offset_t hint_length,
282 283 bool skip_compression);
283 284 int calculateXrefStreamPadding(int xref_bytes);
284 285  
... ...
include/qpdf/QPDFXRefEntry.hh
... ... @@ -23,12 +23,12 @@ class QPDFXRefEntry
23 23 QPDF_DLL
24 24 QPDFXRefEntry();
25 25 QPDF_DLL
26   - QPDFXRefEntry(int type, off_t field1, int field2);
  26 + QPDFXRefEntry(int type, qpdf_offset_t field1, int field2);
27 27  
28 28 QPDF_DLL
29 29 int getType() const;
30 30 QPDF_DLL
31   - off_t getOffset() const; // only for type 1
  31 + qpdf_offset_t getOffset() const; // only for type 1
32 32 QPDF_DLL
33 33 int getObjStreamNumber() const; // only for type 2
34 34 QPDF_DLL
... ... @@ -36,7 +36,7 @@ class QPDFXRefEntry
36 36  
37 37 private:
38 38 int type;
39   - off_t field1;
  39 + qpdf_offset_t field1;
40 40 int field2;
41 41 };
42 42  
... ...
include/qpdf/QUtil.hh
... ... @@ -10,7 +10,6 @@
10 10  
11 11 #include <qpdf/DLL.h>
12 12 #include <qpdf/Types.h>
13   -
14 13 #include <string>
15 14 #include <list>
16 15 #include <stdexcept>
... ... @@ -26,6 +25,9 @@ namespace QUtil
26 25 QPDF_DLL
27 26 std::string double_to_string(double, int decimal_places = 0);
28 27  
  28 + QPDF_DLL
  29 + long long string_to_ll(char const* str);
  30 +
29 31 // Throw std::runtime_error with a string formed by appending to
30 32 // "description: " the standard string corresponding to the
31 33 // current value of errno.
... ... @@ -48,9 +50,9 @@ namespace QUtil
48 50  
49 51 // Wrap around off_t versions of fseek and ftell if available
50 52 QPDF_DLL
51   - int fseek_off_t(FILE* stream, off_t offset, int whence);
  53 + int fseek_off_t(FILE* stream, qpdf_offset_t offset, int whence);
52 54 QPDF_DLL
53   - off_t ftell_off_t(FILE* stream);
  55 + qpdf_offset_t ftell_off_t(FILE* stream);
54 56  
55 57 QPDF_DLL
56 58 char* copy_string(std::string const&);
... ...
include/qpdf/Types.h
1 1 #ifndef __QPDFTYPES_H__
2 2 #define __QPDFTYPES_H__
3 3  
4   -/* This file must be included before any system files. It should be
5   - * included right after <qpdf/DLL.h> within the library.
  4 +/* Provide an offset type that should be as big as off_t on just about
  5 + * any system. If your compiler doesn't support C99 (or at least the
  6 + * "long long" type), then you may have to modify this definition.
6 7 */
7 8  
8   -/* Attempt to provide off_t and size_t on any recent platform. To
9   - * make cross compilation easier and to be more portable across
10   - * platforms, QPDF avoids having any public header files use the
11   - * results of autoconf testing, so we have to handle this ourselves in
12   - * a static way.
13   - */
14   -
15   -#define _FILE_OFFSET_BITS 64
16   -#include <sys/types.h>
17   -#include <stdio.h>
18   -#include <string.h>
  9 +typedef long long int qpdf_offset_t;
19 10  
20 11 #endif /* __QPDFTYPES_H__ */
... ...
include/qpdf/qpdf-c.h
... ... @@ -72,6 +72,7 @@
72 72 #include <qpdf/DLL.h>
73 73 #include <qpdf/Types.h>
74 74 #include <qpdf/Constants.h>
  75 +#include <string.h>
75 76  
76 77 #ifdef __cplusplus
77 78 extern "C" {
... ...
libqpdf/Pl_Count.cc
... ... @@ -28,7 +28,7 @@ Pl_Count::finish()
28 28 getNext()->finish();
29 29 }
30 30  
31   -off_t
  31 +qpdf_offset_t
32 32 Pl_Count::getCount() const
33 33 {
34 34 return this->count;
... ...
libqpdf/QPDF.cc
... ... @@ -18,12 +18,12 @@
18 18 std::string QPDF::qpdf_version = "2.3.1";
19 19  
20 20 void
21   -QPDF::InputSource::setLastOffset(off_t offset)
  21 +QPDF::InputSource::setLastOffset(qpdf_offset_t offset)
22 22 {
23 23 this->last_offset = offset;
24 24 }
25 25  
26   -off_t
  26 +qpdf_offset_t
27 27 QPDF::InputSource::getLastOffset() const
28 28 {
29 29 return this->last_offset;
... ... @@ -36,7 +36,7 @@ QPDF::InputSource::readLine()
36 36 // without caring what the exact terminator is. Consume the
37 37 // trailing newline characters but don't return them.
38 38  
39   - off_t offset = this->tell();
  39 + qpdf_offset_t offset = this->tell();
40 40 std::string buf;
41 41 enum { st_before_nl, st_at_nl } state = st_before_nl;
42 42 char ch;
... ... @@ -126,14 +126,14 @@ QPDF::FileInputSource::getName() const
126 126 return this->filename;
127 127 }
128 128  
129   -off_t
  129 +qpdf_offset_t
130 130 QPDF::FileInputSource::tell()
131 131 {
132 132 return QUtil::ftell_off_t(this->file);
133 133 }
134 134  
135 135 void
136   -QPDF::FileInputSource::seek(off_t offset, int whence)
  136 +QPDF::FileInputSource::seek(qpdf_offset_t offset, int whence)
137 137 {
138 138 QUtil::os_wrapper(std::string("seek to ") + this->filename + ", offset " +
139 139 QUtil::int_to_string(offset) + " (" +
... ... @@ -193,14 +193,14 @@ QPDF::BufferInputSource::getName() const
193 193 return this->description;
194 194 }
195 195  
196   -off_t
  196 +qpdf_offset_t
197 197 QPDF::BufferInputSource::tell()
198 198 {
199 199 return this->cur_offset;
200 200 }
201 201  
202 202 void
203   -QPDF::BufferInputSource::seek(off_t offset, int whence)
  203 +QPDF::BufferInputSource::seek(qpdf_offset_t offset, int whence)
204 204 {
205 205 switch (whence)
206 206 {
... ... @@ -209,7 +209,7 @@ QPDF::BufferInputSource::seek(off_t offset, int whence)
209 209 break;
210 210  
211 211 case SEEK_END:
212   - this->cur_offset = (off_t)this->buf->getSize() + offset;
  212 + this->cur_offset = (qpdf_offset_t)this->buf->getSize() + offset;
213 213 break;
214 214  
215 215 case SEEK_CUR:
... ... @@ -232,7 +232,7 @@ QPDF::BufferInputSource::rewind()
232 232 size_t
233 233 QPDF::BufferInputSource::read(char* buffer, size_t length)
234 234 {
235   - off_t end_pos = (off_t) this->buf->getSize();
  235 + qpdf_offset_t end_pos = (qpdf_offset_t) this->buf->getSize();
236 236 if (this->cur_offset >= end_pos)
237 237 {
238 238 this->last_offset = end_pos;
... ... @@ -453,7 +453,7 @@ QPDF::parse(char const* password)
453 453 throw QPDFExc(qpdf_e_damaged_pdf, this->file->getName(), "", 0,
454 454 "can't find startxref");
455 455 }
456   - off_t xref_offset = atol(m2.getMatch(1).c_str());
  456 + qpdf_offset_t xref_offset = QUtil::string_to_ll(m2.getMatch(1).c_str());
457 457 read_xref(xref_offset);
458 458 }
459 459 catch (QPDFExc& e)
... ... @@ -524,7 +524,7 @@ QPDF::reconstruct_xref(QPDFExc&amp; e)
524 524 }
525 525  
526 526 this->file->seek(0, SEEK_END);
527   - off_t eof = this->file->tell();
  527 + qpdf_offset_t eof = this->file->tell();
528 528 this->file->seek(0, SEEK_SET);
529 529 bool in_obj = false;
530 530 while (this->file->tell() < eof)
... ... @@ -591,7 +591,7 @@ QPDF::reconstruct_xref(QPDFExc&amp; e)
591 591 }
592 592  
593 593 void
594   -QPDF::read_xref(off_t xref_offset)
  594 +QPDF::read_xref(qpdf_offset_t xref_offset)
595 595 {
596 596 std::map<int, int> free_table;
597 597 while (xref_offset)
... ... @@ -634,7 +634,7 @@ QPDF::read_xref(off_t xref_offset)
634 634 }
635 635  
636 636 int
637   -QPDF::read_xrefTable(off_t xref_offset)
  637 +QPDF::read_xrefTable(qpdf_offset_t xref_offset)
638 638 {
639 639 PCRE xref_first_re("^\\s*(\\d+)\\s+(\\d+)");
640 640 PCRE xref_entry_re("(?s:(^\\d{10}) (\\d{5}) ([fn])[ \r\n]{2}$)");
... ... @@ -692,7 +692,7 @@ QPDF::read_xrefTable(off_t xref_offset)
692 692 insertXrefEntry(i, 1, f1, f2);
693 693 }
694 694 }
695   - off_t pos = this->file->tell();
  695 + qpdf_offset_t pos = this->file->tell();
696 696 QPDFTokenizer::Token t = readToken(this->file);
697 697 if (t == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "trailer"))
698 698 {
... ... @@ -791,7 +791,7 @@ QPDF::read_xrefTable(off_t xref_offset)
791 791 }
792 792  
793 793 int
794   -QPDF::read_xrefStream(off_t xref_offset)
  794 +QPDF::read_xrefStream(qpdf_offset_t xref_offset)
795 795 {
796 796 bool found = false;
797 797 if (! this->ignore_xref_streams)
... ... @@ -830,7 +830,7 @@ QPDF::read_xrefStream(off_t xref_offset)
830 830 }
831 831  
832 832 int
833   -QPDF::processXRefStream(off_t xref_offset, QPDFObjectHandle& xref_obj)
  833 +QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj)
834 834 {
835 835 QPDFObjectHandle dict = xref_obj.getDict();
836 836 QPDFObjectHandle W_obj = dict.getKey("/W");
... ... @@ -1123,7 +1123,7 @@ QPDF::readObject(PointerHolder&lt;InputSource&gt; input,
1123 1123 int objid, int generation, bool in_object_stream)
1124 1124 {
1125 1125 setLastObjectDescription(description, objid, generation);
1126   - off_t offset = input->tell();
  1126 + qpdf_offset_t offset = input->tell();
1127 1127 QPDFObjectHandle object = readObjectInternal(
1128 1128 input, objid, generation, in_object_stream, false, false);
1129 1129 // Override last_offset so that it points to the beginning of the
... ... @@ -1149,7 +1149,7 @@ QPDF::readObjectInternal(PointerHolder&lt;InputSource&gt; input,
1149 1149  
1150 1150 QPDFObjectHandle object;
1151 1151  
1152   - off_t offset = input->tell();
  1152 + qpdf_offset_t offset = input->tell();
1153 1153 std::vector<QPDFObjectHandle> olist;
1154 1154 bool done = false;
1155 1155 while (! done)
... ... @@ -1347,7 +1347,7 @@ QPDF::readObjectInternal(PointerHolder&lt;InputSource&gt; input,
1347 1347 if (! in_object_stream)
1348 1348 {
1349 1349 // check for stream
1350   - off_t cur_offset = input->tell();
  1350 + qpdf_offset_t cur_offset = input->tell();
1351 1351 if (readToken(input) ==
1352 1352 QPDFTokenizer::Token(QPDFTokenizer::tt_word, "stream"))
1353 1353 {
... ... @@ -1416,7 +1416,7 @@ QPDF::readObjectInternal(PointerHolder&lt;InputSource&gt; input,
1416 1416 // Must get offset before accessing any additional
1417 1417 // objects since resolving a previously unresolved
1418 1418 // indirect object will change file position.
1419   - off_t stream_offset = input->tell();
  1419 + qpdf_offset_t stream_offset = input->tell();
1420 1420 size_t length = 0;
1421 1421  
1422 1422 try
... ... @@ -1440,7 +1440,8 @@ QPDF::readObjectInternal(PointerHolder&lt;InputSource&gt; input,
1440 1440 }
1441 1441  
1442 1442 length = length_obj.getIntValue();
1443   - input->seek(stream_offset + (off_t)length, SEEK_SET);
  1443 + input->seek(
  1444 + stream_offset + (qpdf_offset_t)length, SEEK_SET);
1444 1445 if (! (readToken(input) ==
1445 1446 QPDFTokenizer::Token(
1446 1447 QPDFTokenizer::tt_word, "endstream")))
... ... @@ -1480,7 +1481,8 @@ QPDF::readObjectInternal(PointerHolder&lt;InputSource&gt; input,
1480 1481  
1481 1482 size_t
1482 1483 QPDF::recoverStreamLength(PointerHolder<InputSource> input,
1483   - int objid, int generation, off_t stream_offset)
  1484 + int objid, int generation,
  1485 + qpdf_offset_t stream_offset)
1484 1486 {
1485 1487 PCRE endobj_re("^\\s*endobj\\b");
1486 1488  
... ... @@ -1491,10 +1493,10 @@ QPDF::recoverStreamLength(PointerHolder&lt;InputSource&gt; input,
1491 1493 "attempting to recover stream length"));
1492 1494  
1493 1495 input->seek(0, SEEK_END);
1494   - off_t eof = input->tell();
  1496 + qpdf_offset_t eof = input->tell();
1495 1497 input->seek(stream_offset, SEEK_SET);
1496 1498 std::string last_line;
1497   - off_t last_line_offset = 0;
  1499 + qpdf_offset_t last_line_offset = 0;
1498 1500 size_t length = 0;
1499 1501 while (input->tell() < eof)
1500 1502 {
... ... @@ -1568,7 +1570,7 @@ QPDF::recoverStreamLength(PointerHolder&lt;InputSource&gt; input,
1568 1570 QPDFTokenizer::Token
1569 1571 QPDF::readToken(PointerHolder<InputSource> input)
1570 1572 {
1571   - off_t offset = input->tell();
  1573 + qpdf_offset_t offset = input->tell();
1572 1574 QPDFTokenizer::Token token;
1573 1575 bool unread_char;
1574 1576 char char_to_unread;
... ... @@ -1611,7 +1613,7 @@ QPDF::readToken(PointerHolder&lt;InputSource&gt; input)
1611 1613  
1612 1614 QPDFObjectHandle
1613 1615 QPDF::readObjectAtOffset(bool try_recovery,
1614   - off_t offset, std::string const& description,
  1616 + qpdf_offset_t offset, std::string const& description,
1615 1617 int exp_objid, int exp_generation,
1616 1618 int& objid, int& generation)
1617 1619 {
... ... @@ -1663,7 +1665,7 @@ QPDF::readObjectAtOffset(bool try_recovery,
1663 1665 if (this->xref_table.count(og) &&
1664 1666 (this->xref_table[og].getType() == 1))
1665 1667 {
1666   - off_t new_offset = this->xref_table[og].getOffset();
  1668 + qpdf_offset_t new_offset = this->xref_table[og].getOffset();
1667 1669 QPDFObjectHandle result = readObjectAtOffset(
1668 1670 false, new_offset, description,
1669 1671 exp_objid, exp_generation, objid, generation);
... ... @@ -1717,7 +1719,7 @@ QPDF::readObjectAtOffset(bool try_recovery,
1717 1719 // linearization hint tables. Offsets and lengths of objects
1718 1720 // may imply the end of an object to be anywhere between these
1719 1721 // values.
1720   - off_t end_before_space = this->file->tell();
  1722 + qpdf_offset_t end_before_space = this->file->tell();
1721 1723  
1722 1724 // skip over spaces
1723 1725 while (true)
... ... @@ -1738,7 +1740,7 @@ QPDF::readObjectAtOffset(bool try_recovery,
1738 1740 "EOF after endobj");
1739 1741 }
1740 1742 }
1741   - off_t end_after_space = this->file->tell();
  1743 + qpdf_offset_t end_after_space = this->file->tell();
1742 1744  
1743 1745 this->obj_cache[og] =
1744 1746 ObjCache(QPDFObjectHandle::ObjAccessor::getObject(oh),
... ... @@ -1768,7 +1770,7 @@ QPDF::resolve(int objid, int generation)
1768 1770 {
1769 1771 case 1:
1770 1772 {
1771   - off_t offset = entry.getOffset();
  1773 + qpdf_offset_t offset = entry.getOffset();
1772 1774 // Object stored in cache by readObjectAtOffset
1773 1775 int aobjid;
1774 1776 int ageneration;
... ... @@ -1812,8 +1814,10 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
1812 1814 // For linearization data in the object, use the data from the
1813 1815 // object stream for the objects in the stream.
1814 1816 ObjGen stream_og(obj_stream_number, 0);
1815   - off_t end_before_space = this->obj_cache[stream_og].end_before_space;
1816   - off_t end_after_space = this->obj_cache[stream_og].end_after_space;
  1817 + qpdf_offset_t end_before_space =
  1818 + this->obj_cache[stream_og].end_before_space;
  1819 + qpdf_offset_t end_after_space =
  1820 + this->obj_cache[stream_og].end_after_space;
1817 1821  
1818 1822 QPDFObjectHandle dict = obj_stream.getDict();
1819 1823 if (! (dict.getKey("/Type").isName() &&
... ... @@ -2102,7 +2106,7 @@ QPDF::getCompressibleObjects()
2102 2106  
2103 2107 void
2104 2108 QPDF::pipeStreamData(int objid, int generation,
2105   - off_t offset, size_t length,
  2109 + qpdf_offset_t offset, size_t length,
2106 2110 QPDFObjectHandle stream_dict,
2107 2111 Pipeline* pipeline)
2108 2112 {
... ...
libqpdf/QPDFExc.cc
... ... @@ -4,7 +4,7 @@
4 4 QPDFExc::QPDFExc(qpdf_error_code_e error_code,
5 5 std::string const& filename,
6 6 std::string const& object,
7   - off_t offset,
  7 + qpdf_offset_t offset,
8 8 std::string const& message) :
9 9 std::runtime_error(createWhat(filename, object, offset, message)),
10 10 error_code(error_code),
... ... @@ -22,7 +22,7 @@ QPDFExc::~QPDFExc() throw ()
22 22 std::string
23 23 QPDFExc::createWhat(std::string const& filename,
24 24 std::string const& object,
25   - off_t offset,
  25 + qpdf_offset_t offset,
26 26 std::string const& message)
27 27 {
28 28 std::string result;
... ... @@ -73,7 +73,7 @@ QPDFExc::getObject() const
73 73 return this->object;
74 74 }
75 75  
76   -off_t
  76 +qpdf_offset_t
77 77 QPDFExc::getFilePosition() const
78 78 {
79 79 return this->offset;
... ...
libqpdf/QPDFObjectHandle.cc
... ... @@ -632,7 +632,7 @@ QPDFObjectHandle::newDictionary(
632 632 QPDFObjectHandle
633 633 QPDFObjectHandle::newStream(QPDF* qpdf, int objid, int generation,
634 634 QPDFObjectHandle stream_dict,
635   - off_t offset, size_t length)
  635 + qpdf_offset_t offset, size_t length)
636 636 {
637 637 return QPDFObjectHandle(new QPDF_Stream(
638 638 qpdf, objid, generation,
... ...
libqpdf/QPDFWriter.cc
... ... @@ -879,7 +879,7 @@ QPDFWriter::writeTrailer(trailer_e which, int size, bool xref_stream, int prev)
879 879 if (which == t_lin_first)
880 880 {
881 881 writeString(" /Prev ");
882   - off_t pos = this->pipeline->getCount();
  882 + qpdf_offset_t pos = this->pipeline->getCount();
883 883 writeString(QUtil::int_to_string(prev));
884 884 int nspaces = (int)(pos - this->pipeline->getCount() + 11);
885 885 assert(nspaces >= 0);
... ... @@ -1165,7 +1165,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
1165 1165 }
1166 1166  
1167 1167 void
1168   -QPDFWriter::writeObjectStreamOffsets(std::vector<off_t>& offsets,
  1168 +QPDFWriter::writeObjectStreamOffsets(std::vector<qpdf_offset_t>& offsets,
1169 1169 int first_obj)
1170 1170 {
1171 1171 for (unsigned int i = 0; i < offsets.size(); ++i)
... ... @@ -1191,8 +1191,8 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
1191 1191 int old_id = object.getObjectID();
1192 1192 int new_id = obj_renumber[old_id];
1193 1193  
1194   - std::vector<off_t> offsets;
1195   - off_t first = 0;
  1194 + std::vector<qpdf_offset_t> offsets;
  1195 + qpdf_offset_t first = 0;
1196 1196  
1197 1197 // Generate stream itself. We have to do this in two passes so we
1198 1198 // can calculate offsets in the first pass.
... ... @@ -1210,7 +1210,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
1210 1210 // Adjust offsets to skip over comment before first object
1211 1211  
1212 1212 first = offsets[0];
1213   - for (std::vector<off_t>::iterator iter = offsets.begin();
  1213 + for (std::vector<qpdf_offset_t>::iterator iter = offsets.begin();
1214 1214 iter != offsets.end(); ++iter)
1215 1215 {
1216 1216 *iter -= first;
... ... @@ -1820,13 +1820,14 @@ QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size)
1820 1820 int
1821 1821 QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size,
1822 1822 int prev, bool suppress_offsets,
1823   - int hint_id, off_t hint_offset, off_t hint_length)
  1823 + int hint_id, qpdf_offset_t hint_offset,
  1824 + qpdf_offset_t hint_length)
1824 1825 {
1825 1826 writeString("xref\n");
1826 1827 writeString(QUtil::int_to_string(first));
1827 1828 writeString(" ");
1828 1829 writeString(QUtil::int_to_string(last - first + 1));
1829   - off_t space_before_zero = this->pipeline->getCount();
  1830 + qpdf_offset_t space_before_zero = this->pipeline->getCount();
1830 1831 writeString("\n");
1831 1832 for (int i = first; i <= last; ++i)
1832 1833 {
... ... @@ -1868,10 +1869,11 @@ int
1868 1869 QPDFWriter::writeXRefStream(int xref_id, int max_id, int max_offset,
1869 1870 trailer_e which, int first, int last, int size,
1870 1871 int prev, int hint_id,
1871   - off_t hint_offset, off_t hint_length,
  1872 + qpdf_offset_t hint_offset,
  1873 + qpdf_offset_t hint_length,
1872 1874 bool skip_compression)
1873 1875 {
1874   - off_t xref_offset = this->pipeline->getCount();
  1876 + qpdf_offset_t xref_offset = this->pipeline->getCount();
1875 1877 int space_before_zero = xref_offset - 1;
1876 1878  
1877 1879 // field 1 contains offsets and object stream identifiers
... ... @@ -2081,13 +2083,13 @@ QPDFWriter::writeLinearized()
2081 2083  
2082 2084 int part4_end_marker = part4.back().getObjectID();
2083 2085 int part6_end_marker = part6.back().getObjectID();
2084   - off_t space_before_zero = 0;
2085   - off_t file_size = 0;
2086   - off_t part6_end_offset = 0;
2087   - off_t first_half_max_obj_offset = 0;
2088   - off_t second_xref_offset = 0;
2089   - off_t first_xref_end = 0;
2090   - off_t second_xref_end = 0;
  2086 + qpdf_offset_t space_before_zero = 0;
  2087 + qpdf_offset_t file_size = 0;
  2088 + qpdf_offset_t part6_end_offset = 0;
  2089 + qpdf_offset_t first_half_max_obj_offset = 0;
  2090 + qpdf_offset_t second_xref_offset = 0;
  2091 + qpdf_offset_t first_xref_end = 0;
  2092 + qpdf_offset_t second_xref_end = 0;
2091 2093  
2092 2094 this->next_objid = part4_first_obj;
2093 2095 enqueuePart(part4);
... ... @@ -2101,7 +2103,7 @@ QPDFWriter::writeLinearized()
2101 2103 enqueuePart(part9);
2102 2104 assert(this->next_objid == after_second_half);
2103 2105  
2104   - off_t hint_length = 0;
  2106 + qpdf_offset_t hint_length = 0;
2105 2107 PointerHolder<Buffer> hint_buffer;
2106 2108  
2107 2109 // Write file in two passes. Part numbers refer to PDF spec 1.4.
... ... @@ -2122,7 +2124,7 @@ QPDFWriter::writeLinearized()
2122 2124 // space if all numerical values in the parameter dictionary
2123 2125 // are 10 digits long plus a few extra characters for safety.
2124 2126  
2125   - off_t pos = this->pipeline->getCount();
  2127 + qpdf_offset_t pos = this->pipeline->getCount();
2126 2128 openObject(lindict_id);
2127 2129 writeString("<<");
2128 2130 if (pass == 2)
... ... @@ -2158,8 +2160,8 @@ QPDFWriter::writeLinearized()
2158 2160  
2159 2161 // Part 3: first page cross reference table and trailer.
2160 2162  
2161   - off_t first_xref_offset = this->pipeline->getCount();
2162   - off_t hint_offset = 0;
  2163 + qpdf_offset_t first_xref_offset = this->pipeline->getCount();
  2164 + qpdf_offset_t hint_offset = 0;
2163 2165 if (pass == 2)
2164 2166 {
2165 2167 hint_offset = this->xref[hint_id].getOffset();
... ... @@ -2187,7 +2189,7 @@ QPDFWriter::writeLinearized()
2187 2189 hint_length + second_xref_offset,
2188 2190 hint_id, hint_offset, hint_length,
2189 2191 (pass == 1));
2190   - off_t endpos = this->pipeline->getCount();
  2192 + qpdf_offset_t endpos = this->pipeline->getCount();
2191 2193 if (pass == 1)
2192 2194 {
2193 2195 // Pad so we have enough room for the real xref
... ... @@ -2264,7 +2266,7 @@ QPDFWriter::writeLinearized()
2264 2266 t_lin_second, 0, second_half_end,
2265 2267 second_trailer_size,
2266 2268 0, 0, 0, 0, (pass == 1));
2267   - off_t endpos = this->pipeline->getCount();
  2269 + qpdf_offset_t endpos = this->pipeline->getCount();
2268 2270  
2269 2271 if (pass == 1)
2270 2272 {
... ... @@ -2278,14 +2280,14 @@ QPDFWriter::writeLinearized()
2278 2280 else
2279 2281 {
2280 2282 // Make the file size the same.
2281   - off_t pos = this->pipeline->getCount();
  2283 + qpdf_offset_t pos = this->pipeline->getCount();
2282 2284 writePad(second_xref_end + hint_length - 1 - pos);
2283 2285 writeString("\n");
2284 2286  
2285 2287 // If this assertion fails, maybe we didn't have
2286 2288 // enough padding above.
2287 2289 assert(this->pipeline->getCount() ==
2288   - (off_t)(second_xref_end + hint_length));
  2290 + (qpdf_offset_t)(second_xref_end + hint_length));
2289 2291 }
2290 2292 }
2291 2293 else
... ... @@ -2313,7 +2315,7 @@ QPDFWriter::writeLinearized()
2313 2315 activatePipelineStack();
2314 2316 writeHintStream(hint_id);
2315 2317 popPipelineStack(&hint_buffer);
2316   - hint_length = (off_t)hint_buffer->getSize();
  2318 + hint_length = (qpdf_offset_t)hint_buffer->getSize();
2317 2319  
2318 2320 // Restore hint offset
2319 2321 this->xref[hint_id] = QPDFXRefEntry(1, hint_offset, 0);
... ... @@ -2358,7 +2360,7 @@ QPDFWriter::writeStandard()
2358 2360 }
2359 2361  
2360 2362 // Now write out xref. next_objid is now the number of objects.
2361   - off_t xref_offset = this->pipeline->getCount();
  2363 + qpdf_offset_t xref_offset = this->pipeline->getCount();
2362 2364 if (this->object_stream_to_objects.empty())
2363 2365 {
2364 2366 // Write regular cross-reference table
... ...
libqpdf/QPDFXRefEntry.cc
... ... @@ -9,7 +9,7 @@ QPDFXRefEntry::QPDFXRefEntry() :
9 9 {
10 10 }
11 11  
12   -QPDFXRefEntry::QPDFXRefEntry(int type, off_t field1, int field2) :
  12 +QPDFXRefEntry::QPDFXRefEntry(int type, qpdf_offset_t field1, int field2) :
13 13 type(type),
14 14 field1(field1),
15 15 field2(field2)
... ... @@ -27,7 +27,7 @@ QPDFXRefEntry::getType() const
27 27 return this->type;
28 28 }
29 29  
30   -off_t
  30 +qpdf_offset_t
31 31 QPDFXRefEntry::getOffset() const
32 32 {
33 33 if (this->type != 1)
... ...
libqpdf/QPDF_Stream.cc
... ... @@ -22,7 +22,7 @@ std::map&lt;std::string, std::string&gt; QPDF_Stream::filter_abbreviations;
22 22  
23 23 QPDF_Stream::QPDF_Stream(QPDF* qpdf, int objid, int generation,
24 24 QPDFObjectHandle stream_dict,
25   - off_t offset, size_t length) :
  25 + qpdf_offset_t offset, size_t length) :
26 26 qpdf(qpdf),
27 27 objid(objid),
28 28 generation(generation),
... ... @@ -379,8 +379,8 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool filter,
379 379 Pl_Count count("stream provider count", pipeline);
380 380 this->stream_provider->provideStreamData(
381 381 this->objid, this->generation, &count);
382   - off_t actual_length = count.getCount();
383   - off_t desired_length =
  382 + qpdf_offset_t actual_length = count.getCount();
  383 + qpdf_offset_t desired_length =
384 384 this->stream_dict.getKey("/Length").getIntValue();
385 385 if (actual_length == desired_length)
386 386 {
... ...
libqpdf/QPDF_linearization.cc
... ... @@ -305,15 +305,15 @@ QPDF::readLinearizationData()
305 305 }
306 306  
307 307 QPDFObjectHandle
308   -QPDF::readHintStream(Pipeline& pl, off_t offset, size_t length)
  308 +QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length)
309 309 {
310 310 int obj;
311 311 int gen;
312 312 QPDFObjectHandle H = readObjectAtOffset(
313 313 false, offset, "linearization hint stream", -1, 0, obj, gen);
314 314 ObjCache& oc = this->obj_cache[ObjGen(obj, gen)];
315   - off_t min_end_offset = oc.end_before_space;
316   - off_t max_end_offset = oc.end_after_space;
  315 + qpdf_offset_t min_end_offset = oc.end_before_space;
  316 + qpdf_offset_t max_end_offset = oc.end_after_space;
317 317 if (! H.isStream())
318 318 {
319 319 throw QPDFExc(qpdf_e_damaged_pdf, this->file->getName(),
... ... @@ -345,7 +345,7 @@ QPDF::readHintStream(Pipeline&amp; pl, off_t offset, size_t length)
345 345 {
346 346 QTC::TC("qpdf", "QPDF hint table length direct");
347 347 }
348   - off_t computed_end = offset + (off_t)length;
  348 + qpdf_offset_t computed_end = offset + (qpdf_offset_t)length;
349 349 if ((computed_end < min_end_offset) ||
350 350 (computed_end > max_end_offset))
351 351 {
... ...
libqpdf/QUtil.cc
... ... @@ -82,6 +82,16 @@ QUtil::double_to_string(double num, int decimal_places)
82 82 return std::string(t);
83 83 }
84 84  
  85 +long long
  86 +QUtil::string_to_ll(char const* str)
  87 +{
  88 +#ifdef _MSC_VER
  89 + return _strtoi64(str, 0, 10);
  90 +#else
  91 + return strtoll(str, 0, 10);
  92 +#endif
  93 +}
  94 +
85 95 void
86 96 QUtil::throw_system_error(std::string const& description)
87 97 {
... ... @@ -109,22 +119,22 @@ QUtil::fopen_wrapper(std::string const&amp; description, FILE* f)
109 119 }
110 120  
111 121 int
112   -QUtil::fseek_off_t(FILE* stream, off_t offset, int whence)
  122 +QUtil::fseek_off_t(FILE* stream, qpdf_offset_t offset, int whence)
113 123 {
114 124 #if HAVE_FSEEKO
115   - return fseeko(stream, offset, whence);
  125 + return fseeko(stream, (off_t)offset, whence);
116 126 #else
117   - return fseek(stream, offset, whence);
  127 + return fseek(stream, (long)offset, whence);
118 128 #endif
119 129 }
120 130  
121   -off_t
  131 +qpdf_offset_t
122 132 QUtil::ftell_off_t(FILE* stream)
123 133 {
124 134 #if HAVE_FSEEKO
125   - return ftello(stream);
  135 + return (qpdf_offset_t)ftello(stream);
126 136 #else
127   - return ftell(stream);
  137 + return (qpdf_offset_t)ftell(stream);
128 138 #endif
129 139 }
130 140  
... ...
libqpdf/qpdf/QPDF_Stream.hh
... ... @@ -14,7 +14,7 @@ class QPDF_Stream: public QPDFObject
14 14 public:
15 15 QPDF_Stream(QPDF*, int objid, int generation,
16 16 QPDFObjectHandle stream_dict,
17   - off_t offset, size_t length);
  17 + qpdf_offset_t offset, size_t length);
18 18 virtual ~QPDF_Stream();
19 19 virtual std::string unparse();
20 20 QPDFObjectHandle getDict() const;
... ... @@ -51,7 +51,7 @@ class QPDF_Stream: public QPDFObject
51 51 int objid;
52 52 int generation;
53 53 QPDFObjectHandle stream_dict;
54   - off_t offset;
  54 + qpdf_offset_t offset;
55 55 size_t length;
56 56 PointerHolder<Buffer> stream_data;
57 57 PointerHolder<QPDFObjectHandle::StreamDataProvider> stream_provider;
... ...