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