From: Lukáš Lalinský Date: Tue, 20 Nov 2012 13:15:16 +0000 (+0100) Subject: Fix opening of read-only files on Windows X-Git-Tag: v1.9~94^2~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ade8dc1a218e43c3909c4eede58f4e28e09da73a;p=taglib Fix opening of read-only files on Windows The CreateFile* functions return INVALID_HANDLE_VALUE on error, not NULL. http://article.gmane.org/gmane.comp.kde.devel.taglib/2346 --- diff --git a/taglib/toolkit/tfilestream.cpp b/taglib/toolkit/tfilestream.cpp index 16efb579..35300de6 100644 --- a/taglib/toolkit/tfilestream.cpp +++ b/taglib/toolkit/tfilestream.cpp @@ -56,10 +56,16 @@ namespace { { DWORD access = readOnly ? GENERIC_READ : (GENERIC_READ | GENERIC_WRITE); + HANDLE handle; if(wcslen(path) > 0) - return CreateFileW(path, access, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + handle = CreateFileW(path, access, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); else - return CreateFileA(path, access, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + handle = CreateFileA(path, access, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + + if(handle == INVALID_HANDLE_VALUE) + handle = NULL; + + return handle; } size_t fread(void *ptr, size_t size, size_t nmemb, HANDLE stream)