Fan.Sys.MmapBuf.open C# (CSharp) Method

open() private method

private open ( string name, string mode, bool existing, uint size ) : void
name string
mode string
existing bool
size uint
return void
        internal void open(string name, string mode, bool existing, uint size)
        {
            // file mode
              FileRights fr; FileProtection fp;
              if (mode == "r")       { fr = FileRights.Read; fp = FileProtection.ReadOnly; }
              else if (mode == "rw") { fr = FileRights.ReadWrite; fp = FileProtection.ReadWrite; }
              else if (mode == "p") throw ArgErr.make("Private mode not supported.").val;
              else throw ArgErr.make("Invalid mode: " + mode).val;

              if (existing)
              {
            m_fileHandle = OpenFileMapping(fr, false, name);
            if (m_fileHandle == IntPtr.Zero)
              throw IOErr.make("Open error: " + Marshal.GetLastWin32Error()).val;
              }
              else
              {
            m_fileHandle = CreateFileMapping(NoFileHandle, 0, fp, 0, size, name);
            if (m_fileHandle == IntPtr.Zero)
              throw IOErr.make("Create error: " + Marshal.GetLastWin32Error()).val;
              }

              // Obtain a read/write map for the entire file
              m_fileMap = MapViewOfFile(m_fileHandle, fr, 0, 0, 0);

              if (m_fileMap == IntPtr.Zero)
            throw IOErr.make("MapViewOfFile error: " + Marshal.GetLastWin32Error()).val;
        }