From 04f871cc4cbf8cd8ee3a1a0abfb2deaad6eeb451 Mon Sep 17 00:00:00 2001 From: Robin Mills Date: Mon, 11 Jan 2016 10:03:48 +0000 Subject: [PATCH] #1152 Fix submitted. Also added new static function FileIo::temporaryPath() which I require for tgt - code and fixed typo in tiffvisitor.cpp --- include/exiv2/basicio.hpp | 5 +++++ src/basicio.cpp | 28 +++++++++++++++++++++++++--- src/tiffvisitor.cpp | 2 +- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/include/exiv2/basicio.hpp b/include/exiv2/basicio.hpp index 3aac9e8c..669eed6a 100644 --- a/include/exiv2/basicio.hpp +++ b/include/exiv2/basicio.hpp @@ -544,6 +544,11 @@ namespace Exiv2 { virtual void populateFakeData(); //@} + /*! + @brief Returns the path to a temporary data storage location. + */ + static std::string temporaryPath(); + private: // NOT IMPLEMENTED //! Copy constructor diff --git a/src/basicio.cpp b/src/basicio.cpp index 326a72e4..f22ce347 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -273,7 +273,7 @@ namespace Exiv2 { # if defined(EXV_UNICODE_PATH) # error No xattr API for MacOS X with unicode support # endif - const ssize_t namebufSize = ::listxattr(src.p_->path_.c_str(), 0, 0, 0); + ssize_t namebufSize = ::listxattr(src.p_->path_.c_str(), 0, 0, 0); if (namebufSize < 0) { throw Error(2, src.p_->path_, strError(), "listxattr"); } @@ -282,7 +282,7 @@ namespace Exiv2 { return; } char* namebuf = new char[namebufSize]; - if (::listxattr(src.p_->path_.c_str(), namebuf, sizeof(namebuf), 0) != namebufSize) { + if (::listxattr(src.p_->path_.c_str(), namebuf, namebufSize, 0) != namebufSize) { throw Error(2, src.p_->path_, strError(), "listxattr"); } for (ssize_t namebufPos = 0; namebufPos < namebufSize;) { @@ -293,7 +293,7 @@ namespace Exiv2 { throw Error(2, src.p_->path_, strError(), "getxattr"); } char* value = new char[valueSize]; - if (::getxattr(src.p_->path_.c_str(), name, value, sizeof(value), 0, 0) != valueSize) { + if (::getxattr(src.p_->path_.c_str(), name, value, valueSize, 0, 0) != valueSize) { throw Error(2, src.p_->path_, strError(), "getxattr"); } // #906. Mountain Lion 'sandbox' terminates the app when we call setxattr @@ -619,6 +619,28 @@ namespace Exiv2 { return basicIo; } + std::string FileIo::temporaryPath() + { + static int count = 0 ; + char sCount[12]; + sprintf(sCount,"_%d",count++); + +#ifdef _MSC_VER + char lpTempPathBuffer[MAX_PATH]; + GetTempPath(MAX_PATH,lpTempPathBuffer); + std::string tmp(lpTempPathBuffer); + tmp += "\\"; +#else + std::string tmp = "/tmp/"; +#endif + + pid_t pid = ::getpid(); + std::string result = tmp + toString(pid) + sCount ; + if ( Exiv2::fileExists(result) ) std::remove(result.c_str()); + + return result; + } + long FileIo::write(const byte* data, long wcount) { assert(p_->fp_ != 0); diff --git a/src/tiffvisitor.cpp b/src/tiffvisitor.cpp index fb9de367..815e1692 100644 --- a/src/tiffvisitor.cpp +++ b/src/tiffvisitor.cpp @@ -1541,7 +1541,7 @@ namespace Exiv2 { // Sadly: we don't know the exact location of the image in the source (it's near offset) // And neither TiffReader nor TiffEntryBase have access to the BasicIo object being processed byte* buffer = (byte*) ::malloc(isize); - ::memset(buffer,isize,0); + ::memset(buffer,0,isize); v->read(buffer,isize, byteOrder()); ::free(buffer); }