From 57b8ae6e1ca4822164d19865ef7ef1e8aee8b941 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Tue, 20 Nov 2012 22:20:34 +0900 Subject: [PATCH] Fix reading read-only files in Win32 --- taglib/toolkit/tfilestream.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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)); } } -- 2.40.0