From 7eac9bbe9268d9b690a8919f107a717322b91e54 Mon Sep 17 00:00:00 2001 From: Andreas Huggel Date: Wed, 18 Jan 2006 11:34:45 +0000 Subject: [PATCH] Fixes for MinGW and MSVC --- msvc/exiv2lib/exiv2lib.vcproj | 3 +++ msvc/exivsimple/exivsimple.h | 2 +- src/Makefile | 38 +++++++++++++++++++++++------------ src/crwimage.cpp | 15 +++++++------- src/types.cpp | 23 +++++++++++++++++++++ src/types.hpp | 8 ++++++++ 6 files changed, 68 insertions(+), 21 deletions(-) diff --git a/msvc/exiv2lib/exiv2lib.vcproj b/msvc/exiv2lib/exiv2lib.vcproj index 3f7f8f49..9cfc6e8a 100644 --- a/msvc/exiv2lib/exiv2lib.vcproj +++ b/msvc/exiv2lib/exiv2lib.vcproj @@ -253,6 +253,9 @@ + + #include #include +#include #ifndef EXV_HAVE_TIMEGM # include "timegm.h" #endif @@ -242,7 +242,7 @@ namespace Exiv2 { // Write new buffer to file BasicIo::AutoPtr tempIo(io_->temporary()); // may throw assert (tempIo.get() != 0); - tempIo->write(&blob[0], blob.size()); + tempIo->write(&blob[0], static_cast(blob.size())); io_->close(); io_->transfer(*tempIo); // may throw @@ -1004,7 +1004,7 @@ namespace Exiv2 { if (tm) { const size_t m = 20; char s[m]; - std::strftime(s, m, "%Y:%m:%d %T", tm); + std::strftime(s, m, "%Y:%m:%d %H:%M:%S", tm); ExifKey key(pCrwMapping->tag_, ExifTags::ifdItem(pCrwMapping->ifdId_)); AsciiValue value; @@ -1132,7 +1132,7 @@ namespace Exiv2 { CiffComponent* cc = pHead->findComponent(pCrwMapping->crwTagId_, pCrwMapping->crwDir_); if (!comment.empty()) { - uint32_t size = comment.size(); + uint32_t size = static_cast(comment.size()); if (cc && cc->size() > size) size = cc->size(); DataBuf buf(size); memset(buf.pData_, 0x0, buf.size_); @@ -1197,7 +1197,7 @@ namespace Exiv2 { } if (buf.size_ > 0) { // Write the number of shorts to the beginning of buf - us2Data(buf.pData_, buf.size_, pHead->byteOrder()); + us2Data(buf.pData_, static_cast(buf.size_), pHead->byteOrder()); pHead->add(pCrwMapping->crwTagId_, pCrwMapping->crwDir_, buf); } else { @@ -1217,8 +1217,9 @@ namespace Exiv2 { const ExifData::const_iterator ed = image.exifData().findKey(key); if (ed != image.exifData().end()) { struct tm tm; - char* p = strptime(ed->toString().c_str(), "%Y:%m:%d %T", &tm); - if (p != 0) t = timegm(&tm); + memset(&tm, 0x0, sizeof(tm)); + int rc = exifTime(ed->toString().c_str(), &tm); + if (rc == 0) t = timegm(&tm); } if (t != 0) { DataBuf buf(12); diff --git a/src/types.cpp b/src/types.cpp index 2f4d2b19..7bc26b2a 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -40,6 +40,9 @@ EXIV2_RCSID("@(#) $Id$"); #include #include #include +#include +#include +#include // ***************************************************************************** // class member definitions @@ -311,4 +314,24 @@ namespace Exiv2 { return true; } // isHex + int exifTime(const char* buf, struct tm* tm) + { + assert(buf != 0); + assert(tm != 0); + int rc = 1; + int year, mon, mday, hour, min, sec; + int scanned = sscanf(buf, "%4d:%2d:%2d %2d:%2d:%2d", + &year, &mon, &mday, &hour, &min, &sec); + if (scanned == 6) { + tm->tm_year = year - 1900; + tm->tm_mon = mon - 1; + tm->tm_mday = mday; + tm->tm_hour = hour; + tm->tm_min = min; + tm->tm_sec = sec; + rc = 0; + } + return rc; + } // exifTime + } // namespace Exiv2 diff --git a/src/types.hpp b/src/types.hpp index 22665253..44330e77 100644 --- a/src/types.hpp +++ b/src/types.hpp @@ -48,6 +48,7 @@ #ifdef EXV_HAVE_STDINT_H # include #endif +#include // MSVC doesn't provide C99 types, but it has MS specific variants #ifdef _MSC_VER @@ -284,6 +285,13 @@ namespace Exiv2 { size_t size =0, const std::string& prefix =""); + /*! + @brief Converts a string in the form "%Y:%m:%d %H:%M:%S", e.g., + "2007:05:24 12:31:55" to broken down time format, + returns 0 if successful, else 1. + */ + int exifTime(const char* buf, struct tm* tm); + // ***************************************************************************** // template and inline definitions