Skip to content

Commit

Permalink
Fix reading read-only files in Win32
Browse files Browse the repository at this point in the history
  • Loading branch information
TsudaKageyu committed Nov 20, 2012
1 parent c6f7ad3 commit 57b8ae6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions taglib/toolkit/tfilestream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ namespace {

// Using native file handles instead of file descriptors for reducing the resource consumption.

const HANDLE InvalidFile = INVALID_HANDLE_VALUE;

HANDLE openFile(const FileName &path, bool readOnly)
{
DWORD access = readOnly ? GENERIC_READ : (GENERIC_READ | GENERIC_WRITE);
Expand Down Expand Up @@ -82,6 +84,8 @@ namespace {

// For non-Windows

const FILE *InvalidFile = 0;

struct FileNameHandle : public std::string
{
FileNameHandle(FileName name) : std::string(name) {}
Expand Down Expand Up @@ -119,7 +123,7 @@ class FileStream::FileStreamPrivate
};

FileStream::FileStreamPrivate::FileStreamPrivate(FileName fileName, bool openReadOnly) :
file(0),
file(InvalidFile),
name(fileName),
readOnly(true),
size(0)
Expand All @@ -129,12 +133,12 @@ FileStream::FileStreamPrivate::FileStreamPrivate(FileName fileName, bool openRea
if(!openReadOnly)
file = openFile(name, false);

if(file)
if(file != InvalidFile)
readOnly = false;
else
file = openFile(name, true);

if(!file) {
if(file == InvalidFile) {
debug("Could not open file " + String((const char *) name));
}
}
Expand Down

0 comments on commit 57b8ae6

Please sign in to comment.