diff --git a/include/exiv2/basicio.hpp b/include/exiv2/basicio.hpp index 4deef29d..39a14bc6 100644 --- a/include/exiv2/basicio.hpp +++ b/include/exiv2/basicio.hpp @@ -551,7 +551,11 @@ namespace Exiv2 { /*! @brief Returns the path to a temporary data storage location. */ - static std::string temporaryPath(); +#ifdef EXV_UNICODE_PATH + static std::wstring temporaryPath(); +#else + static std::string temporaryPath(); +#endif private: // NOT IMPLEMENTED diff --git a/include/exiv2/config.h b/include/exiv2/config.h index 83fef53e..15e0e23f 100644 --- a/include/exiv2/config.h +++ b/include/exiv2/config.h @@ -165,6 +165,9 @@ typedef int pid_t; # ifdef EXV_HAVE_REGEX # undef EXV_HAVE_REGEX # endif +#ifdef EXV_UNICODE_PATH +#error EXV_UNICODE_PATH is not supported for MinGW builds +#endif #endif #ifndef __CYGWIN__ diff --git a/include/exiv2/exv_msvc.h b/include/exiv2/exv_msvc.h index e809ee69..b335ced4 100644 --- a/include/exiv2/exv_msvc.h +++ b/include/exiv2/exv_msvc.h @@ -51,7 +51,7 @@ #endif /* !EXV_COMMERCIAL_VERSION */ /* Define Windows unicode path support. */ -/* #undef EXV_UNICODE_PATH */ +/* #define EXV_UNICODE_PATH */ /* Define to `const' or to empty, depending on the second argument of `iconv'. */ diff --git a/include/exiv2/types.hpp b/include/exiv2/types.hpp index c22b71c9..2f7a8a3f 100644 --- a/include/exiv2/types.hpp +++ b/include/exiv2/types.hpp @@ -363,7 +363,6 @@ namespace Exiv2 { EXIV2API std::wstring s2ws(const std::string& s); //! Convert a unicode std::wstring s to an std::string. EXIV2API std::string ws2s(const std::wstring& s); - #endif /*! @brief Return a \em long set to the value represented by \em s. diff --git a/src/actions.cpp b/src/actions.cpp index bb5f7dfd..c999dd76 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -2071,7 +2071,11 @@ namespace { Action::Modify::applyCommands(sourceImage.get()); // Open or create the target file - std::string target = bStdout ? Exiv2::FileIo::temporaryPath() : tgt; +#ifdef EXV_UNICODE_PATH + std::string target = bStdout ? Exiv2::ws2s(Exiv2::FileIo::temporaryPath()) : tgt; +#else + std::string target = bStdout ? Exiv2::FileIo::temporaryPath() : tgt; +#endif Exiv2::Image::AutoPtr targetImage; if (Exiv2::fileExists(target)) { diff --git a/src/basicio.cpp b/src/basicio.cpp index f3f79708..d2fadec6 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -577,46 +577,56 @@ namespace Exiv2 { #else nlink_t nlink = buf.st_nlink; #endif - +#ifdef EXV_UNICODE_PATH + std::wstring tmpname; +#else + std::string tmpname; +#endif // If file is > 1MB and doesn't have hard links then use a file, otherwise // use a memory buffer. I.e., files with hard links always use a memory // buffer, which is a workaround to ensure that the links don't get broken. - if (ret != 0 || (buf.st_size > 1048576 && nlink == 1)) { + if (ret != 0 || (buf.st_size > 1048576 && nlink == 1)) + { pid_t pid = ::getpid(); std::auto_ptr fileIo; #ifdef EXV_UNICODE_PATH - if (p_->wpMode_ == Impl::wpUnicode) { - std::wstring tmpname = wpath() + s2ws(toString(pid)); - fileIo = std::auto_ptr(new FileIo(tmpname)); - } - else + tmpname = temporaryPath() + s2ws(toString(pid)); + fileIo = std::auto_ptr(new FileIo(tmpname)); +#else + tmpname = temporaryPath() + toString(pid); + fileIo = std::auto_ptr(new FileIo(tmpname)); #endif - { - std::string tmpname = path() + toString(pid); - fileIo = std::auto_ptr(new FileIo(tmpname)); - } if (fileIo->open("w+b") != 0) { #ifdef EXV_UNICODE_PATH - if (p_->wpMode_ == Impl::wpUnicode) { - throw WError(10, wpath(), "w+b", strError().c_str()); +#if defined(_MSC_VER) + if( !DeleteFileW( tmpname.c_str()) ) + { + perror("Error deleting file"); + throw WError(10, ws2s(tmpname).c_str(), "w+b", strError().c_str()); } - else +#endif +#else +#if defined(_MSC_VER) || defined(__MINGW__) + if( !DeleteFile( tmpname.c_str() ) ) +#else + if( remove( tmpname.c_str() ) != 0 ) +#endif #endif { - throw Error(10, path(), "w+b", strError()); + perror("Error deleting file"); } + throw Error(10, tmpname.c_str(), "w+b", strError()); } fileIo->p_->copyXattrFrom(*this); basicIo = fileIo; - } - else { + } else { basicIo.reset(new MemIo); } return basicIo; } - std::string FileIo::temporaryPath() + static std::string tempPath() { static int count = 0 ; char sCount[12]; @@ -638,6 +648,18 @@ namespace Exiv2 { return result; } +#ifdef EXV_UNICODE_PATH + std::wstring FileIo::temporaryPath() + { + return s2ws(tempPath()); + } +#else + std::string FileIo::temporaryPath() + { + return tempPath(); + } +#endif + long FileIo::write(const byte* data, long wcount) { assert(p_->fp_ != 0);