From: Mikko Rasa Date: Wed, 27 Mar 2013 19:53:20 +0000 (+0200) Subject: Improve file opening on Windows X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=959bb34629f786cd64f666029407e60bdd37d418;p=libs%2Fcore.git Improve file opening on Windows Handle M_RDWR properly Allow multiple concurrent readers --- diff --git a/source/io/file.cpp b/source/io/file.cpp index d4b2da3..805a9e8 100644 --- a/source/io/file.cpp +++ b/source/io/file.cpp @@ -26,11 +26,13 @@ File::File(const string &fn, Mode m, CreateMode cm) #ifdef WIN32 int flags = 0; + int share_flags = 0; int create_flags = OPEN_EXISTING; if(mode&M_READ) flags |= GENERIC_READ; - else if(mode&M_WRITE) + + if(mode&M_WRITE) { flags |= GENERIC_WRITE; @@ -43,8 +45,10 @@ File::File(const string &fn, Mode m, CreateMode cm) case C_NEW: create_flags = CREATE_NEW; break; } } + else + share_flags = FILE_SHARE_READ; - *handle = CreateFile(fn.c_str(), flags, 0, 0, create_flags, FILE_ATTRIBUTE_NORMAL, 0); + *handle = CreateFile(fn.c_str(), flags, share_flags, 0, create_flags, FILE_ATTRIBUTE_NORMAL, 0); if(!handle) { int err = GetLastError();