[Issue 2429] New: std.stream.File incorrect flag parsing and sharing mode

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Oct 24 07:22:00 PDT 2008


http://d.puremagic.com/issues/show_bug.cgi?id=2429

           Summary: std.stream.File incorrect flag parsing and sharing mode
           Product: D
           Version: 1.037
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: jason at spashett.com


In stream.d parseMode is incorrect/inconsistent for windows platforms. 

Firstly the share mode is not set to FILE_SHARE_READ in the case when the file
is opened for writing. This make it impossible to view log files while they are
written to.

Second it is possible to specify combinations of FileMode options which will
override each others behaviour and create a mixture.

Hence it's possible to 'fix' the sharing option but opening a file with:
FileMode.OutNew |  FileMode.In to enable sharing even though the file will
never be read from.

I can't see any indication that this things are by design, and perhaps the
windows sharing mode should always include READ and WRITE sharing to be more
portable. Either that or allow sharing flags in the file mode.



private void parseMode(int mode,
                         out int access,
                         out int share,
                         out int createMode) {
    version (Win32) {
      if (mode & FileMode.In) {
        access |= GENERIC_READ;
        share |= FILE_SHARE_READ;
        createMode = OPEN_EXISTING;
      }
      if (mode & FileMode.Out) {
        access |= GENERIC_WRITE;
        createMode = OPEN_ALWAYS; // will create if not present
      }
      if ((mode & FileMode.OutNew) == FileMode.OutNew) {
        createMode = CREATE_ALWAYS; // resets file
      }
    }


-- 



More information about the Digitalmars-d-bugs mailing list