diff --git a/ChangeLog b/ChangeLog index c422f144..2d6a4b44 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2012-06-21 Jay Berkenbilt + * Instead of using off_t in the public APIs, use qpdf_offset_t + instead. This is defined as long long in qpdf/Types.h. If your + system doesn't support long long, you can redefine it. + * Add pkg-config files * QPDFObjectHandle: add shallowCopy() method diff --git a/configure.ac b/configure.ac index 1ee57347..c1cf187c 100644 --- a/configure.ac +++ b/configure.ac @@ -11,6 +11,7 @@ AC_CONFIG_FILES([libqpdf.pc]) AC_CONFIG_HEADERS([libqpdf/qpdf/qpdf-config.h]) AC_PROG_CC +AC_PROG_CC_C99 AC_PROG_CXX AC_HEADER_STDC LT_INIT([win32-dll]) diff --git a/include/qpdf/Pl_Count.hh b/include/qpdf/Pl_Count.hh index 7e522455..1063fe1d 100644 --- a/include/qpdf/Pl_Count.hh +++ b/include/qpdf/Pl_Count.hh @@ -27,14 +27,14 @@ class Pl_Count: public Pipeline virtual void finish(); // Returns the number of bytes written QPDF_DLL - off_t getCount() const; + qpdf_offset_t getCount() const; // Returns the last character written, or '\0' if no characters // have been written (in which case getCount() returns 0) QPDF_DLL unsigned char getLastChar() const; private: - off_t count; + qpdf_offset_t count; unsigned char last_char; }; diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index 3d53e466..6a910e58 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -394,7 +394,7 @@ class QPDF friend class QPDF_Stream; private: static void pipeStreamData(QPDF* qpdf, int objid, int generation, - off_t offset, size_t length, + qpdf_offset_t offset, size_t length, QPDFObjectHandle dict, Pipeline* pipeline) { @@ -418,19 +418,19 @@ class QPDF { } - void setLastOffset(off_t); - off_t getLastOffset() const; + void setLastOffset(qpdf_offset_t); + qpdf_offset_t getLastOffset() const; std::string readLine(); virtual std::string const& getName() const = 0; - virtual off_t tell() = 0; - virtual void seek(off_t offset, int whence) = 0; + virtual qpdf_offset_t tell() = 0; + virtual void seek(qpdf_offset_t offset, int whence) = 0; virtual void rewind() = 0; virtual size_t read(char* buffer, size_t length) = 0; virtual void unreadCh(char ch) = 0; protected: - off_t last_offset; + qpdf_offset_t last_offset; }; class FileInputSource: public InputSource @@ -441,8 +441,8 @@ class QPDF void setFile(FILE* filep); virtual ~FileInputSource(); virtual std::string const& getName() const; - virtual off_t tell(); - virtual void seek(off_t offset, int whence); + virtual qpdf_offset_t tell(); + virtual void seek(qpdf_offset_t offset, int whence); virtual void rewind(); virtual size_t read(char* buffer, size_t length); virtual void unreadCh(char ch); @@ -465,8 +465,8 @@ class QPDF bool own_memory = false); virtual ~BufferInputSource(); virtual std::string const& getName() const; - virtual off_t tell(); - virtual void seek(off_t offset, int whence); + virtual qpdf_offset_t tell(); + virtual void seek(qpdf_offset_t offset, int whence); virtual void rewind(); virtual size_t read(char* buffer, size_t length); virtual void unreadCh(char ch); @@ -475,7 +475,7 @@ class QPDF bool own_memory; std::string description; Buffer* buf; - off_t cur_offset; + qpdf_offset_t cur_offset; }; class ObjGen @@ -498,8 +498,8 @@ class QPDF { } ObjCache(PointerHolder object, - off_t end_before_space, - off_t end_after_space) : + qpdf_offset_t end_before_space, + qpdf_offset_t end_after_space) : object(object), end_before_space(end_before_space), end_after_space(end_after_space) @@ -507,18 +507,18 @@ class QPDF } PointerHolder object; - off_t end_before_space; - off_t end_after_space; + qpdf_offset_t end_before_space; + qpdf_offset_t end_after_space; }; void parse(char const* password); void warn(QPDFExc const& e); void setTrailer(QPDFObjectHandle obj); - void read_xref(off_t offset); + void read_xref(qpdf_offset_t offset); void reconstruct_xref(QPDFExc& e); - int read_xrefTable(off_t offset); - int read_xrefStream(off_t offset); - int processXRefStream(off_t offset, QPDFObjectHandle& xref_stream); + int read_xrefTable(qpdf_offset_t offset); + int read_xrefStream(qpdf_offset_t offset); + int processXRefStream(qpdf_offset_t offset, QPDFObjectHandle& xref_stream); void insertXrefEntry(int obj, int f0, int f1, int f2, bool overwrite = false); void setLastObjectDescription(std::string const& description, @@ -532,12 +532,12 @@ class QPDF bool in_array, bool in_dictionary); size_t recoverStreamLength( PointerHolder input, int objid, int generation, - off_t stream_offset); + qpdf_offset_t stream_offset); QPDFTokenizer::Token readToken(PointerHolder); QPDFObjectHandle readObjectAtOffset( bool attempt_recovery, - off_t offset, std::string const& description, + qpdf_offset_t offset, std::string const& description, int exp_objid, int exp_generation, int& act_objid, int& act_generation); PointerHolder resolve(int objid, int generation); @@ -545,7 +545,7 @@ class QPDF // Calls finish() on the pipeline when done but does not delete it void pipeStreamData(int objid, int generation, - off_t offset, size_t length, + qpdf_offset_t offset, size_t length, QPDFObjectHandle dict, Pipeline* pipeline); @@ -832,7 +832,8 @@ class QPDF void readLinearizationData(); bool checkLinearizationInternal(); void dumpLinearizationDataInternal(); - QPDFObjectHandle readHintStream(Pipeline&, off_t offset, size_t length); + QPDFObjectHandle readHintStream( + Pipeline&, qpdf_offset_t offset, size_t length); void readHPageOffset(BitStream); void readHSharedObject(BitStream); void readHGeneric(BitStream, HGeneric&); diff --git a/include/qpdf/QPDFExc.hh b/include/qpdf/QPDFExc.hh index f8e23ffb..c306ee1e 100644 --- a/include/qpdf/QPDFExc.hh +++ b/include/qpdf/QPDFExc.hh @@ -21,7 +21,7 @@ class QPDFExc: public std::runtime_error QPDFExc(qpdf_error_code_e error_code, std::string const& filename, std::string const& object, - off_t offset, + qpdf_offset_t offset, std::string const& message); QPDF_DLL virtual ~QPDFExc() throw (); @@ -43,20 +43,20 @@ class QPDFExc: public std::runtime_error QPDF_DLL std::string const& getObject() const; QPDF_DLL - off_t getFilePosition() const; + qpdf_offset_t getFilePosition() const; QPDF_DLL std::string const& getMessageDetail() const; private: static std::string createWhat(std::string const& filename, std::string const& object, - off_t offset, + qpdf_offset_t offset, std::string const& message); qpdf_error_code_e error_code; std::string filename; std::string object; - off_t offset; + qpdf_offset_t offset; std::string message; }; diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh index e431d8a7..4a056185 100644 --- a/include/qpdf/QPDFObjectHandle.hh +++ b/include/qpdf/QPDFObjectHandle.hh @@ -347,7 +347,7 @@ class QPDFObjectHandle // object must be dictionary object static QPDFObjectHandle newStream( QPDF* qpdf, int objid, int generation, - QPDFObjectHandle stream_dict, off_t offset, size_t length) + QPDFObjectHandle stream_dict, qpdf_offset_t offset, size_t length) { return QPDFObjectHandle::newStream( qpdf, objid, generation, stream_dict, offset, length); @@ -395,7 +395,7 @@ class QPDFObjectHandle static QPDFObjectHandle newIndirect(QPDF*, int objid, int generation); static QPDFObjectHandle newStream( QPDF* qpdf, int objid, int generation, - QPDFObjectHandle stream_dict, off_t offset, size_t length); + QPDFObjectHandle stream_dict, qpdf_offset_t offset, size_t length); void assertInitialized() const; void assertType(char const* type_name, bool istype); diff --git a/include/qpdf/QPDFWriter.hh b/include/qpdf/QPDFWriter.hh index 72771f68..bcb9335b 100644 --- a/include/qpdf/QPDFWriter.hh +++ b/include/qpdf/QPDFWriter.hh @@ -221,7 +221,8 @@ class QPDFWriter void writePad(int nspaces); void assignCompressedObjectNumbers(int objid); void enqueueObject(QPDFObjectHandle object); - void writeObjectStreamOffsets(std::vector& offsets, int first_obj); + void writeObjectStreamOffsets( + std::vector& offsets, int first_obj); void writeObjectStream(QPDFObjectHandle object); void writeObject(QPDFObjectHandle object, int object_stream_index = -1); void writeTrailer(trailer_e which, int size, @@ -268,8 +269,8 @@ class QPDFWriter int prev, bool suppress_offsets, int hint_id, - off_t hint_offset, - off_t hint_length); + qpdf_offset_t hint_offset, + qpdf_offset_t hint_length); int writeXRefStream(int objid, int max_id, int max_offset, trailer_e which, int first, int last, int size); int writeXRefStream(int objid, int max_id, int max_offset, @@ -277,8 +278,8 @@ class QPDFWriter // for linearization int prev, int hint_id, - off_t hint_offset, - off_t hint_length, + qpdf_offset_t hint_offset, + qpdf_offset_t hint_length, bool skip_compression); int calculateXrefStreamPadding(int xref_bytes); diff --git a/include/qpdf/QPDFXRefEntry.hh b/include/qpdf/QPDFXRefEntry.hh index c362cc97..f8d3f930 100644 --- a/include/qpdf/QPDFXRefEntry.hh +++ b/include/qpdf/QPDFXRefEntry.hh @@ -23,12 +23,12 @@ class QPDFXRefEntry QPDF_DLL QPDFXRefEntry(); QPDF_DLL - QPDFXRefEntry(int type, off_t field1, int field2); + QPDFXRefEntry(int type, qpdf_offset_t field1, int field2); QPDF_DLL int getType() const; QPDF_DLL - off_t getOffset() const; // only for type 1 + qpdf_offset_t getOffset() const; // only for type 1 QPDF_DLL int getObjStreamNumber() const; // only for type 2 QPDF_DLL @@ -36,7 +36,7 @@ class QPDFXRefEntry private: int type; - off_t field1; + qpdf_offset_t field1; int field2; }; diff --git a/include/qpdf/QUtil.hh b/include/qpdf/QUtil.hh index c253fde3..4d5981de 100644 --- a/include/qpdf/QUtil.hh +++ b/include/qpdf/QUtil.hh @@ -10,7 +10,6 @@ #include #include - #include #include #include @@ -26,6 +25,9 @@ namespace QUtil QPDF_DLL std::string double_to_string(double, int decimal_places = 0); + QPDF_DLL + long long string_to_ll(char const* str); + // Throw std::runtime_error with a string formed by appending to // "description: " the standard string corresponding to the // current value of errno. @@ -48,9 +50,9 @@ namespace QUtil // Wrap around off_t versions of fseek and ftell if available QPDF_DLL - int fseek_off_t(FILE* stream, off_t offset, int whence); + int fseek_off_t(FILE* stream, qpdf_offset_t offset, int whence); QPDF_DLL - off_t ftell_off_t(FILE* stream); + qpdf_offset_t ftell_off_t(FILE* stream); QPDF_DLL char* copy_string(std::string const&); diff --git a/include/qpdf/Types.h b/include/qpdf/Types.h index 439e5c24..0d6b8a2e 100644 --- a/include/qpdf/Types.h +++ b/include/qpdf/Types.h @@ -1,20 +1,11 @@ #ifndef __QPDFTYPES_H__ #define __QPDFTYPES_H__ -/* This file must be included before any system files. It should be - * included right after within the library. +/* Provide an offset type that should be as big as off_t on just about + * any system. If your compiler doesn't support C99 (or at least the + * "long long" type), then you may have to modify this definition. */ -/* Attempt to provide off_t and size_t on any recent platform. To - * make cross compilation easier and to be more portable across - * platforms, QPDF avoids having any public header files use the - * results of autoconf testing, so we have to handle this ourselves in - * a static way. - */ - -#define _FILE_OFFSET_BITS 64 -#include -#include -#include +typedef long long int qpdf_offset_t; #endif /* __QPDFTYPES_H__ */ diff --git a/include/qpdf/qpdf-c.h b/include/qpdf/qpdf-c.h index 3103497c..1a65e4af 100644 --- a/include/qpdf/qpdf-c.h +++ b/include/qpdf/qpdf-c.h @@ -72,6 +72,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { diff --git a/libqpdf/Pl_Count.cc b/libqpdf/Pl_Count.cc index 78516343..c76a5e23 100644 --- a/libqpdf/Pl_Count.cc +++ b/libqpdf/Pl_Count.cc @@ -28,7 +28,7 @@ Pl_Count::finish() getNext()->finish(); } -off_t +qpdf_offset_t Pl_Count::getCount() const { return this->count; diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index dd572fd3..e97da295 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -18,12 +18,12 @@ std::string QPDF::qpdf_version = "2.3.1"; void -QPDF::InputSource::setLastOffset(off_t offset) +QPDF::InputSource::setLastOffset(qpdf_offset_t offset) { this->last_offset = offset; } -off_t +qpdf_offset_t QPDF::InputSource::getLastOffset() const { return this->last_offset; @@ -36,7 +36,7 @@ QPDF::InputSource::readLine() // without caring what the exact terminator is. Consume the // trailing newline characters but don't return them. - off_t offset = this->tell(); + qpdf_offset_t offset = this->tell(); std::string buf; enum { st_before_nl, st_at_nl } state = st_before_nl; char ch; @@ -126,14 +126,14 @@ QPDF::FileInputSource::getName() const return this->filename; } -off_t +qpdf_offset_t QPDF::FileInputSource::tell() { return QUtil::ftell_off_t(this->file); } void -QPDF::FileInputSource::seek(off_t offset, int whence) +QPDF::FileInputSource::seek(qpdf_offset_t offset, int whence) { QUtil::os_wrapper(std::string("seek to ") + this->filename + ", offset " + QUtil::int_to_string(offset) + " (" + @@ -193,14 +193,14 @@ QPDF::BufferInputSource::getName() const return this->description; } -off_t +qpdf_offset_t QPDF::BufferInputSource::tell() { return this->cur_offset; } void -QPDF::BufferInputSource::seek(off_t offset, int whence) +QPDF::BufferInputSource::seek(qpdf_offset_t offset, int whence) { switch (whence) { @@ -209,7 +209,7 @@ QPDF::BufferInputSource::seek(off_t offset, int whence) break; case SEEK_END: - this->cur_offset = (off_t)this->buf->getSize() + offset; + this->cur_offset = (qpdf_offset_t)this->buf->getSize() + offset; break; case SEEK_CUR: @@ -232,7 +232,7 @@ QPDF::BufferInputSource::rewind() size_t QPDF::BufferInputSource::read(char* buffer, size_t length) { - off_t end_pos = (off_t) this->buf->getSize(); + qpdf_offset_t end_pos = (qpdf_offset_t) this->buf->getSize(); if (this->cur_offset >= end_pos) { this->last_offset = end_pos; @@ -453,7 +453,7 @@ QPDF::parse(char const* password) throw QPDFExc(qpdf_e_damaged_pdf, this->file->getName(), "", 0, "can't find startxref"); } - off_t xref_offset = atol(m2.getMatch(1).c_str()); + qpdf_offset_t xref_offset = QUtil::string_to_ll(m2.getMatch(1).c_str()); read_xref(xref_offset); } catch (QPDFExc& e) @@ -524,7 +524,7 @@ QPDF::reconstruct_xref(QPDFExc& e) } this->file->seek(0, SEEK_END); - off_t eof = this->file->tell(); + qpdf_offset_t eof = this->file->tell(); this->file->seek(0, SEEK_SET); bool in_obj = false; while (this->file->tell() < eof) @@ -591,7 +591,7 @@ QPDF::reconstruct_xref(QPDFExc& e) } void -QPDF::read_xref(off_t xref_offset) +QPDF::read_xref(qpdf_offset_t xref_offset) { std::map free_table; while (xref_offset) @@ -634,7 +634,7 @@ QPDF::read_xref(off_t xref_offset) } int -QPDF::read_xrefTable(off_t xref_offset) +QPDF::read_xrefTable(qpdf_offset_t xref_offset) { PCRE xref_first_re("^\\s*(\\d+)\\s+(\\d+)"); PCRE xref_entry_re("(?s:(^\\d{10}) (\\d{5}) ([fn])[ \r\n]{2}$)"); @@ -692,7 +692,7 @@ QPDF::read_xrefTable(off_t xref_offset) insertXrefEntry(i, 1, f1, f2); } } - off_t pos = this->file->tell(); + qpdf_offset_t pos = this->file->tell(); QPDFTokenizer::Token t = readToken(this->file); if (t == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "trailer")) { @@ -791,7 +791,7 @@ QPDF::read_xrefTable(off_t xref_offset) } int -QPDF::read_xrefStream(off_t xref_offset) +QPDF::read_xrefStream(qpdf_offset_t xref_offset) { bool found = false; if (! this->ignore_xref_streams) @@ -830,7 +830,7 @@ QPDF::read_xrefStream(off_t xref_offset) } int -QPDF::processXRefStream(off_t xref_offset, QPDFObjectHandle& xref_obj) +QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) { QPDFObjectHandle dict = xref_obj.getDict(); QPDFObjectHandle W_obj = dict.getKey("/W"); @@ -1123,7 +1123,7 @@ QPDF::readObject(PointerHolder input, int objid, int generation, bool in_object_stream) { setLastObjectDescription(description, objid, generation); - off_t offset = input->tell(); + qpdf_offset_t offset = input->tell(); QPDFObjectHandle object = readObjectInternal( input, objid, generation, in_object_stream, false, false); // Override last_offset so that it points to the beginning of the @@ -1149,7 +1149,7 @@ QPDF::readObjectInternal(PointerHolder input, QPDFObjectHandle object; - off_t offset = input->tell(); + qpdf_offset_t offset = input->tell(); std::vector olist; bool done = false; while (! done) @@ -1347,7 +1347,7 @@ QPDF::readObjectInternal(PointerHolder input, if (! in_object_stream) { // check for stream - off_t cur_offset = input->tell(); + qpdf_offset_t cur_offset = input->tell(); if (readToken(input) == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "stream")) { @@ -1416,7 +1416,7 @@ QPDF::readObjectInternal(PointerHolder input, // Must get offset before accessing any additional // objects since resolving a previously unresolved // indirect object will change file position. - off_t stream_offset = input->tell(); + qpdf_offset_t stream_offset = input->tell(); size_t length = 0; try @@ -1440,7 +1440,8 @@ QPDF::readObjectInternal(PointerHolder input, } length = length_obj.getIntValue(); - input->seek(stream_offset + (off_t)length, SEEK_SET); + input->seek( + stream_offset + (qpdf_offset_t)length, SEEK_SET); if (! (readToken(input) == QPDFTokenizer::Token( QPDFTokenizer::tt_word, "endstream"))) @@ -1480,7 +1481,8 @@ QPDF::readObjectInternal(PointerHolder input, size_t QPDF::recoverStreamLength(PointerHolder input, - int objid, int generation, off_t stream_offset) + int objid, int generation, + qpdf_offset_t stream_offset) { PCRE endobj_re("^\\s*endobj\\b"); @@ -1491,10 +1493,10 @@ QPDF::recoverStreamLength(PointerHolder input, "attempting to recover stream length")); input->seek(0, SEEK_END); - off_t eof = input->tell(); + qpdf_offset_t eof = input->tell(); input->seek(stream_offset, SEEK_SET); std::string last_line; - off_t last_line_offset = 0; + qpdf_offset_t last_line_offset = 0; size_t length = 0; while (input->tell() < eof) { @@ -1568,7 +1570,7 @@ QPDF::recoverStreamLength(PointerHolder input, QPDFTokenizer::Token QPDF::readToken(PointerHolder input) { - off_t offset = input->tell(); + qpdf_offset_t offset = input->tell(); QPDFTokenizer::Token token; bool unread_char; char char_to_unread; @@ -1611,7 +1613,7 @@ QPDF::readToken(PointerHolder input) QPDFObjectHandle QPDF::readObjectAtOffset(bool try_recovery, - off_t offset, std::string const& description, + qpdf_offset_t offset, std::string const& description, int exp_objid, int exp_generation, int& objid, int& generation) { @@ -1663,7 +1665,7 @@ QPDF::readObjectAtOffset(bool try_recovery, if (this->xref_table.count(og) && (this->xref_table[og].getType() == 1)) { - off_t new_offset = this->xref_table[og].getOffset(); + qpdf_offset_t new_offset = this->xref_table[og].getOffset(); QPDFObjectHandle result = readObjectAtOffset( false, new_offset, description, exp_objid, exp_generation, objid, generation); @@ -1717,7 +1719,7 @@ QPDF::readObjectAtOffset(bool try_recovery, // linearization hint tables. Offsets and lengths of objects // may imply the end of an object to be anywhere between these // values. - off_t end_before_space = this->file->tell(); + qpdf_offset_t end_before_space = this->file->tell(); // skip over spaces while (true) @@ -1738,7 +1740,7 @@ QPDF::readObjectAtOffset(bool try_recovery, "EOF after endobj"); } } - off_t end_after_space = this->file->tell(); + qpdf_offset_t end_after_space = this->file->tell(); this->obj_cache[og] = ObjCache(QPDFObjectHandle::ObjAccessor::getObject(oh), @@ -1768,7 +1770,7 @@ QPDF::resolve(int objid, int generation) { case 1: { - off_t offset = entry.getOffset(); + qpdf_offset_t offset = entry.getOffset(); // Object stored in cache by readObjectAtOffset int aobjid; int ageneration; @@ -1812,8 +1814,10 @@ QPDF::resolveObjectsInStream(int obj_stream_number) // For linearization data in the object, use the data from the // object stream for the objects in the stream. ObjGen stream_og(obj_stream_number, 0); - off_t end_before_space = this->obj_cache[stream_og].end_before_space; - off_t end_after_space = this->obj_cache[stream_og].end_after_space; + qpdf_offset_t end_before_space = + this->obj_cache[stream_og].end_before_space; + qpdf_offset_t end_after_space = + this->obj_cache[stream_og].end_after_space; QPDFObjectHandle dict = obj_stream.getDict(); if (! (dict.getKey("/Type").isName() && @@ -2102,7 +2106,7 @@ QPDF::getCompressibleObjects() void QPDF::pipeStreamData(int objid, int generation, - off_t offset, size_t length, + qpdf_offset_t offset, size_t length, QPDFObjectHandle stream_dict, Pipeline* pipeline) { diff --git a/libqpdf/QPDFExc.cc b/libqpdf/QPDFExc.cc index 1fc9d724..8bbfb0b4 100644 --- a/libqpdf/QPDFExc.cc +++ b/libqpdf/QPDFExc.cc @@ -4,7 +4,7 @@ QPDFExc::QPDFExc(qpdf_error_code_e error_code, std::string const& filename, std::string const& object, - off_t offset, + qpdf_offset_t offset, std::string const& message) : std::runtime_error(createWhat(filename, object, offset, message)), error_code(error_code), @@ -22,7 +22,7 @@ QPDFExc::~QPDFExc() throw () std::string QPDFExc::createWhat(std::string const& filename, std::string const& object, - off_t offset, + qpdf_offset_t offset, std::string const& message) { std::string result; @@ -73,7 +73,7 @@ QPDFExc::getObject() const return this->object; } -off_t +qpdf_offset_t QPDFExc::getFilePosition() const { return this->offset; diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 4e28c405..1c2481f8 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -632,7 +632,7 @@ QPDFObjectHandle::newDictionary( QPDFObjectHandle QPDFObjectHandle::newStream(QPDF* qpdf, int objid, int generation, QPDFObjectHandle stream_dict, - off_t offset, size_t length) + qpdf_offset_t offset, size_t length) { return QPDFObjectHandle(new QPDF_Stream( qpdf, objid, generation, diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc index 2de7d724..3a08c726 100644 --- a/libqpdf/QPDFWriter.cc +++ b/libqpdf/QPDFWriter.cc @@ -879,7 +879,7 @@ QPDFWriter::writeTrailer(trailer_e which, int size, bool xref_stream, int prev) if (which == t_lin_first) { writeString(" /Prev "); - off_t pos = this->pipeline->getCount(); + qpdf_offset_t pos = this->pipeline->getCount(); writeString(QUtil::int_to_string(prev)); int nspaces = (int)(pos - this->pipeline->getCount() + 11); assert(nspaces >= 0); @@ -1165,7 +1165,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, } void -QPDFWriter::writeObjectStreamOffsets(std::vector& offsets, +QPDFWriter::writeObjectStreamOffsets(std::vector& offsets, int first_obj) { for (unsigned int i = 0; i < offsets.size(); ++i) @@ -1191,8 +1191,8 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) int old_id = object.getObjectID(); int new_id = obj_renumber[old_id]; - std::vector offsets; - off_t first = 0; + std::vector offsets; + qpdf_offset_t first = 0; // Generate stream itself. We have to do this in two passes so we // can calculate offsets in the first pass. @@ -1210,7 +1210,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) // Adjust offsets to skip over comment before first object first = offsets[0]; - for (std::vector::iterator iter = offsets.begin(); + for (std::vector::iterator iter = offsets.begin(); iter != offsets.end(); ++iter) { *iter -= first; @@ -1820,13 +1820,14 @@ QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size) int QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size, int prev, bool suppress_offsets, - int hint_id, off_t hint_offset, off_t hint_length) + int hint_id, qpdf_offset_t hint_offset, + qpdf_offset_t hint_length) { writeString("xref\n"); writeString(QUtil::int_to_string(first)); writeString(" "); writeString(QUtil::int_to_string(last - first + 1)); - off_t space_before_zero = this->pipeline->getCount(); + qpdf_offset_t space_before_zero = this->pipeline->getCount(); writeString("\n"); for (int i = first; i <= last; ++i) { @@ -1868,10 +1869,11 @@ int QPDFWriter::writeXRefStream(int xref_id, int max_id, int max_offset, trailer_e which, int first, int last, int size, int prev, int hint_id, - off_t hint_offset, off_t hint_length, + qpdf_offset_t hint_offset, + qpdf_offset_t hint_length, bool skip_compression) { - off_t xref_offset = this->pipeline->getCount(); + qpdf_offset_t xref_offset = this->pipeline->getCount(); int space_before_zero = xref_offset - 1; // field 1 contains offsets and object stream identifiers @@ -2081,13 +2083,13 @@ QPDFWriter::writeLinearized() int part4_end_marker = part4.back().getObjectID(); int part6_end_marker = part6.back().getObjectID(); - off_t space_before_zero = 0; - off_t file_size = 0; - off_t part6_end_offset = 0; - off_t first_half_max_obj_offset = 0; - off_t second_xref_offset = 0; - off_t first_xref_end = 0; - off_t second_xref_end = 0; + qpdf_offset_t space_before_zero = 0; + qpdf_offset_t file_size = 0; + qpdf_offset_t part6_end_offset = 0; + qpdf_offset_t first_half_max_obj_offset = 0; + qpdf_offset_t second_xref_offset = 0; + qpdf_offset_t first_xref_end = 0; + qpdf_offset_t second_xref_end = 0; this->next_objid = part4_first_obj; enqueuePart(part4); @@ -2101,7 +2103,7 @@ QPDFWriter::writeLinearized() enqueuePart(part9); assert(this->next_objid == after_second_half); - off_t hint_length = 0; + qpdf_offset_t hint_length = 0; PointerHolder hint_buffer; // Write file in two passes. Part numbers refer to PDF spec 1.4. @@ -2122,7 +2124,7 @@ QPDFWriter::writeLinearized() // space if all numerical values in the parameter dictionary // are 10 digits long plus a few extra characters for safety. - off_t pos = this->pipeline->getCount(); + qpdf_offset_t pos = this->pipeline->getCount(); openObject(lindict_id); writeString("<<"); if (pass == 2) @@ -2158,8 +2160,8 @@ QPDFWriter::writeLinearized() // Part 3: first page cross reference table and trailer. - off_t first_xref_offset = this->pipeline->getCount(); - off_t hint_offset = 0; + qpdf_offset_t first_xref_offset = this->pipeline->getCount(); + qpdf_offset_t hint_offset = 0; if (pass == 2) { hint_offset = this->xref[hint_id].getOffset(); @@ -2187,7 +2189,7 @@ QPDFWriter::writeLinearized() hint_length + second_xref_offset, hint_id, hint_offset, hint_length, (pass == 1)); - off_t endpos = this->pipeline->getCount(); + qpdf_offset_t endpos = this->pipeline->getCount(); if (pass == 1) { // Pad so we have enough room for the real xref @@ -2264,7 +2266,7 @@ QPDFWriter::writeLinearized() t_lin_second, 0, second_half_end, second_trailer_size, 0, 0, 0, 0, (pass == 1)); - off_t endpos = this->pipeline->getCount(); + qpdf_offset_t endpos = this->pipeline->getCount(); if (pass == 1) { @@ -2278,14 +2280,14 @@ QPDFWriter::writeLinearized() else { // Make the file size the same. - off_t pos = this->pipeline->getCount(); + qpdf_offset_t pos = this->pipeline->getCount(); writePad(second_xref_end + hint_length - 1 - pos); writeString("\n"); // If this assertion fails, maybe we didn't have // enough padding above. assert(this->pipeline->getCount() == - (off_t)(second_xref_end + hint_length)); + (qpdf_offset_t)(second_xref_end + hint_length)); } } else @@ -2313,7 +2315,7 @@ QPDFWriter::writeLinearized() activatePipelineStack(); writeHintStream(hint_id); popPipelineStack(&hint_buffer); - hint_length = (off_t)hint_buffer->getSize(); + hint_length = (qpdf_offset_t)hint_buffer->getSize(); // Restore hint offset this->xref[hint_id] = QPDFXRefEntry(1, hint_offset, 0); @@ -2358,7 +2360,7 @@ QPDFWriter::writeStandard() } // Now write out xref. next_objid is now the number of objects. - off_t xref_offset = this->pipeline->getCount(); + qpdf_offset_t xref_offset = this->pipeline->getCount(); if (this->object_stream_to_objects.empty()) { // Write regular cross-reference table diff --git a/libqpdf/QPDFXRefEntry.cc b/libqpdf/QPDFXRefEntry.cc index dea3aab6..847fc8e6 100644 --- a/libqpdf/QPDFXRefEntry.cc +++ b/libqpdf/QPDFXRefEntry.cc @@ -9,7 +9,7 @@ QPDFXRefEntry::QPDFXRefEntry() : { } -QPDFXRefEntry::QPDFXRefEntry(int type, off_t field1, int field2) : +QPDFXRefEntry::QPDFXRefEntry(int type, qpdf_offset_t field1, int field2) : type(type), field1(field1), field2(field2) @@ -27,7 +27,7 @@ QPDFXRefEntry::getType() const return this->type; } -off_t +qpdf_offset_t QPDFXRefEntry::getOffset() const { if (this->type != 1) diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc index dc6692bb..ed5fb5be 100644 --- a/libqpdf/QPDF_Stream.cc +++ b/libqpdf/QPDF_Stream.cc @@ -22,7 +22,7 @@ std::map QPDF_Stream::filter_abbreviations; QPDF_Stream::QPDF_Stream(QPDF* qpdf, int objid, int generation, QPDFObjectHandle stream_dict, - off_t offset, size_t length) : + qpdf_offset_t offset, size_t length) : qpdf(qpdf), objid(objid), generation(generation), @@ -379,8 +379,8 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool filter, Pl_Count count("stream provider count", pipeline); this->stream_provider->provideStreamData( this->objid, this->generation, &count); - off_t actual_length = count.getCount(); - off_t desired_length = + qpdf_offset_t actual_length = count.getCount(); + qpdf_offset_t desired_length = this->stream_dict.getKey("/Length").getIntValue(); if (actual_length == desired_length) { diff --git a/libqpdf/QPDF_linearization.cc b/libqpdf/QPDF_linearization.cc index d4e98dde..48bb4d2b 100644 --- a/libqpdf/QPDF_linearization.cc +++ b/libqpdf/QPDF_linearization.cc @@ -305,15 +305,15 @@ QPDF::readLinearizationData() } QPDFObjectHandle -QPDF::readHintStream(Pipeline& pl, off_t offset, size_t length) +QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length) { int obj; int gen; QPDFObjectHandle H = readObjectAtOffset( false, offset, "linearization hint stream", -1, 0, obj, gen); ObjCache& oc = this->obj_cache[ObjGen(obj, gen)]; - off_t min_end_offset = oc.end_before_space; - off_t max_end_offset = oc.end_after_space; + qpdf_offset_t min_end_offset = oc.end_before_space; + qpdf_offset_t max_end_offset = oc.end_after_space; if (! H.isStream()) { throw QPDFExc(qpdf_e_damaged_pdf, this->file->getName(), @@ -345,7 +345,7 @@ QPDF::readHintStream(Pipeline& pl, off_t offset, size_t length) { QTC::TC("qpdf", "QPDF hint table length direct"); } - off_t computed_end = offset + (off_t)length; + qpdf_offset_t computed_end = offset + (qpdf_offset_t)length; if ((computed_end < min_end_offset) || (computed_end > max_end_offset)) { diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc index e1071940..3c3bf011 100644 --- a/libqpdf/QUtil.cc +++ b/libqpdf/QUtil.cc @@ -82,6 +82,16 @@ QUtil::double_to_string(double num, int decimal_places) return std::string(t); } +long long +QUtil::string_to_ll(char const* str) +{ +#ifdef _MSC_VER + return _strtoi64(str, 0, 10); +#else + return strtoll(str, 0, 10); +#endif +} + void QUtil::throw_system_error(std::string const& description) { @@ -109,22 +119,22 @@ QUtil::fopen_wrapper(std::string const& description, FILE* f) } int -QUtil::fseek_off_t(FILE* stream, off_t offset, int whence) +QUtil::fseek_off_t(FILE* stream, qpdf_offset_t offset, int whence) { #if HAVE_FSEEKO - return fseeko(stream, offset, whence); + return fseeko(stream, (off_t)offset, whence); #else - return fseek(stream, offset, whence); + return fseek(stream, (long)offset, whence); #endif } -off_t +qpdf_offset_t QUtil::ftell_off_t(FILE* stream) { #if HAVE_FSEEKO - return ftello(stream); + return (qpdf_offset_t)ftello(stream); #else - return ftell(stream); + return (qpdf_offset_t)ftell(stream); #endif } diff --git a/libqpdf/qpdf/QPDF_Stream.hh b/libqpdf/qpdf/QPDF_Stream.hh index 49db4d47..e74ae201 100644 --- a/libqpdf/qpdf/QPDF_Stream.hh +++ b/libqpdf/qpdf/QPDF_Stream.hh @@ -14,7 +14,7 @@ class QPDF_Stream: public QPDFObject public: QPDF_Stream(QPDF*, int objid, int generation, QPDFObjectHandle stream_dict, - off_t offset, size_t length); + qpdf_offset_t offset, size_t length); virtual ~QPDF_Stream(); virtual std::string unparse(); QPDFObjectHandle getDict() const; @@ -51,7 +51,7 @@ class QPDF_Stream: public QPDFObject int objid; int generation; QPDFObjectHandle stream_dict; - off_t offset; + qpdf_offset_t offset; size_t length; PointerHolder stream_data; PointerHolder stream_provider;