From: Tsuda Kageyu Date: Tue, 20 Nov 2012 13:20:34 +0000 (+0900) Subject: Fix reading read-only files in Win32 X-Git-Tag: v1.9~94^2~8^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=57b8ae6e1ca4822164d19865ef7ef1e8aee8b941;p=taglib Fix reading read-only files in Win32 --- diff --git a/taglib/toolkit/tfilestream.cpp b/taglib/toolkit/tfilestream.cpp index 16efb579..d68dbc82 100644 --- a/taglib/toolkit/tfilestream.cpp +++ b/taglib/toolkit/tfilestream.cpp @@ -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); @@ -82,6 +84,8 @@ namespace { // For non-Windows + const FILE *InvalidFile = 0; + struct FileNameHandle : public std::string { FileNameHandle(FileName name) : std::string(name) {} @@ -119,7 +123,7 @@ public: }; FileStream::FileStreamPrivate::FileStreamPrivate(FileName fileName, bool openReadOnly) : - file(0), + file(InvalidFile), name(fileName), readOnly(true), size(0) @@ -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)); } }