From a9987ab57042ce755261492d93cb54d9ff10fc35 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sun, 12 Jul 2009 22:52:13 +0000 Subject: Fix a few compiler errors reported correctly my MSVC 9.0. Fix libtests test suites to pass on Windows, mostly by dealing with ascii vs. binary and NL vs. CRNL change ($td->NORMALIZE_NEWLINES). Convert some test suites to use fread instead of read. PCRE.hh: define PCRE_STATIC if on Windows. Provide cross-platform function for getting current time instead of using time(0). git-svn-id: svn+q:///qpdf/trunk@678 71b93d88-0707-0410-a8cf-f5a4172ac649 --- libqpdf/QPDF.cc | 2 +- libqpdf/QPDFWriter.cc | 2 +- libqpdf/QPDF_encryption.cc | 2 +- libqpdf/QPDF_linearization.cc | 2 +- libqpdf/QUtil.cc | 26 ++++++++++++++++++++++++++ libqpdf/qpdf/PCRE.hh | 3 +++ 6 files changed, 33 insertions(+), 4 deletions(-) (limited to 'libqpdf') diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index bcee47a4..0385828d 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -241,7 +241,7 @@ QPDF::ObjGen::ObjGen(int o = 0, int g = 0) : } bool -QPDF::ObjGen::ObjGen::operator<(ObjGen const& rhs) const +QPDF::ObjGen::operator<(ObjGen const& rhs) const { return ((this->obj < rhs.obj) || ((this->obj == rhs.obj) && (this->gen < rhs.gen))); diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc index acaf52a8..eb146bd2 100644 --- a/libqpdf/QPDFWriter.cc +++ b/libqpdf/QPDFWriter.cc @@ -1110,7 +1110,7 @@ QPDFWriter::generateID() // the file yet. This scheme should be fine though. std::string seed; - seed += QUtil::int_to_string((int)time(0)); + seed += QUtil::int_to_string((int)QUtil::get_current_time()); seed += " QPDF "; seed += filename; seed += " "; diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc index 39b34070..bd7ef7a6 100644 --- a/libqpdf/QPDF_encryption.cc +++ b/libqpdf/QPDF_encryption.cc @@ -45,7 +45,7 @@ QPDF::trim_user_password(std::string& user_password) return; } - char* p = 0; + char const* p = 0; while ((p = strchr(cstr, '\x28')) != 0) { if (memcmp(p, padding_string, len - (p - cstr)) == 0) diff --git a/libqpdf/QPDF_linearization.cc b/libqpdf/QPDF_linearization.cc index 9a1c7b05..5739b3a9 100644 --- a/libqpdf/QPDF_linearization.cc +++ b/libqpdf/QPDF_linearization.cc @@ -624,7 +624,7 @@ QPDF::maxEnd(ObjUser const& ou) assert(this->obj_user_to_objects.count(ou) > 0); std::set const& ogs = this->obj_user_to_objects[ou]; int end = 0; - for (std::set::iterator iter = ogs.begin(); + for (std::set::const_iterator iter = ogs.begin(); iter != ogs.end(); ++iter) { ObjGen const& og = *iter; diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc index 0ffc6e26..3ac467d4 100644 --- a/libqpdf/QUtil.cc +++ b/libqpdf/QUtil.cc @@ -141,6 +141,32 @@ QUtil::get_env(std::string const& var, std::string* value) #endif } +time_t +QUtil::get_current_time() +{ +#ifdef _WIN32 + // The procedure to get local time at this resolution comes from + // the Microsoft documentation. It says to convert a SYSTEMTIME + // to a FILETIME, and to copy the FILETIME to a ULARGE_INTEGER. + // The resulting number is the number of 100-nanosecond intervals + // between January 1, 1601 and now. POSIX threads wants a time + // based on January 1, 1970, so we adjust by subtracting the + // number of seconds in that time period from the result we get + // here. + SYSTEMTIME sysnow; + GetSystemTime(&sysnow); + FILETIME filenow; + SystemTimeToFileTime(&sysnow, &filenow); + ULARGE_INTEGER uinow; + uinow.LowPart = filenow.dwLowDateTime; + uinow.HighPart = filenow.dwHighDateTime; + ULONGLONG now = uinow.QuadPart; + return ((now / 10000000LL) - 11644473600LL); +#else + return time(0); +#endif +} + std::string QUtil::toUTF8(unsigned long uval) { diff --git a/libqpdf/qpdf/PCRE.hh b/libqpdf/qpdf/PCRE.hh index a226aa19..deba8733 100644 --- a/libqpdf/qpdf/PCRE.hh +++ b/libqpdf/qpdf/PCRE.hh @@ -5,6 +5,9 @@ #ifndef __PCRE_HH__ #define __PCRE_HH__ +#ifdef _WIN32 +# define PCRE_STATIC +#endif #include #include -- cgit v1.2.3-54-g00ecf