mirror of
https://github.com/taglib/taglib.git
synced 2025-05-27 21:20:26 -04:00
Merge pull request #85 from TsudaKageyu/fix-readonly
Fix reading read-only files in Win32
This commit is contained in:
commit
3da792152a
@ -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);
|
||||
@ -88,6 +90,8 @@ namespace {
|
||||
|
||||
// For non-Windows
|
||||
|
||||
FILE *const InvalidFile = 0;
|
||||
|
||||
struct FileNameHandle : public std::string
|
||||
{
|
||||
FileNameHandle(FileName name) : std::string(name) {}
|
||||
@ -125,7 +129,7 @@ public:
|
||||
};
|
||||
|
||||
FileStream::FileStreamPrivate::FileStreamPrivate(FileName fileName, bool openReadOnly) :
|
||||
file(0),
|
||||
file(InvalidFile),
|
||||
name(fileName),
|
||||
readOnly(true),
|
||||
size(0)
|
||||
@ -135,12 +139,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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user