#671: Fixed error handling for read-only files.

v0.27.3
Andreas Huggel 16 years ago
parent ec9bf9a142
commit ade0b51b79

@ -297,7 +297,9 @@ namespace Exiv2 {
} }
p_->mappedLength_ = size(); p_->mappedLength_ = size();
p_->isWriteable_ = isWriteable; p_->isWriteable_ = isWriteable;
if (p_->isWriteable_ && p_->switchMode(Impl::opWrite) != 0) return 0; if (p_->isWriteable_ && p_->switchMode(Impl::opWrite) != 0) {
throw Error(16, path(), strError());
}
#if defined EXV_HAVE_MMAP && defined EXV_HAVE_MUNMAP #if defined EXV_HAVE_MMAP && defined EXV_HAVE_MUNMAP
int prot = PROT_READ; int prot = PROT_READ;
if (p_->isWriteable_) { if (p_->isWriteable_) {
@ -343,7 +345,9 @@ namespace Exiv2 {
#else #else
// Workaround for platforms without mmap: Read the file into memory // Workaround for platforms without mmap: Read the file into memory
DataBuf buf(static_cast<long>(p_->mappedLength_)); DataBuf buf(static_cast<long>(p_->mappedLength_));
read(buf.pData_, buf.size_); if (read(buf.pData_, buf.size_) != buf.size_) {
throw Error(2, path(), strError(), "FileIo::read");
}
if (error() || eof()) throw Error(2, path(), strError(), "FileIo::mmap"); if (error() || eof()) throw Error(2, path(), strError(), "FileIo::mmap");
p_->pMappedArea_ = buf.release().first; p_->pMappedArea_ = buf.release().first;
p_->isMalloced_ = true; p_->isMalloced_ = true;

@ -67,7 +67,7 @@ namespace {
{ 13, N_("Image type %1 is not supported") }, // %1=image type { 13, N_("Image type %1 is not supported") }, // %1=image type
{ 14, N_("Failed to read image data") }, { 14, N_("Failed to read image data") },
{ 15, N_("This does not look like a JPEG image") }, { 15, N_("This does not look like a JPEG image") },
// { 16, N_("") }, -- currently not used { 16, N_("%1: Failed to map file for reading and writing: %2") }, // %1=path, %2=strerror
{ 17, N_("%1: Failed to rename file to %2: %3") }, // %1=old path, %2=new path, %3=strerror { 17, N_("%1: Failed to rename file to %2: %3") }, // %1=old path, %2=new path, %3=strerror
{ 18, N_("%1: Transfer failed: %2") }, // %1=path, %2=strerror { 18, N_("%1: Transfer failed: %2") }, // %1=path, %2=strerror
{ 19, N_("Memory transfer failed: %1") }, // %1=strerror { 19, N_("Memory transfer failed: %1") }, // %1=strerror

Loading…
Cancel
Save