From 959bb34629f786cd64f666029407e60bdd37d418 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 27 Mar 2013 21:53:20 +0200 Subject: [PATCH] Improve file opening on Windows Handle M_RDWR properly Allow multiple concurrent readers --- source/io/file.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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(); -- 2.45.2