]> git.tdb.fi Git - libs/core.git/commitdiff
Improve file opening on Windows
authorMikko Rasa <tdb@tdb.fi>
Wed, 27 Mar 2013 19:53:20 +0000 (21:53 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 27 Mar 2013 19:54:50 +0000 (21:54 +0200)
Handle M_RDWR properly
Allow multiple concurrent readers

source/io/file.cpp

index d4b2da3454f0a29e3ba32808256780ba6aa8954d..805a9e8dba0072270d90a8cb695faa681e710e3a 100644 (file)
@@ -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();