From 81e8752362eeab80f156eb74d1b523eba20a0366 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 21 Jun 2012 19:32:21 -0400 Subject: 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. --- include/qpdf/Pl_Count.hh | 4 ++-- include/qpdf/QPDF.hh | 47 ++++++++++++++++++++-------------------- include/qpdf/QPDFExc.hh | 8 +++---- include/qpdf/QPDFObjectHandle.hh | 4 ++-- include/qpdf/QPDFWriter.hh | 11 +++++----- include/qpdf/QPDFXRefEntry.hh | 6 ++--- include/qpdf/QUtil.hh | 8 ++++--- include/qpdf/Types.h | 17 ++++----------- include/qpdf/qpdf-c.h | 1 + 9 files changed, 51 insertions(+), 55 deletions(-) (limited to 'include') 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" { -- cgit v1.2.3-54-g00ecf