File: Windows.hs

package info (click to toggle)
haskell-foundation 0.0.30-5
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 928 kB
  • sloc: haskell: 9,124; ansic: 570; makefile: 6
file content (26 lines) | stat: -rw-r--r-- 1,002 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module Foundation.Foreign.MemoryMap.Windows
    ( fileMapRead
    ) where

import System.Win32.Mem
import System.Win32.File
import System.Win32.FileMapping
import Control.Exception hiding (handle)

import Basement.Compat.Base
import Basement.Types.OffsetSize
import Foundation.VFS
import Foundation.Foreign.MemoryMap.Types

fileMapRead :: FileMapReadF
fileMapRead path = bracket doOpen closeHandle doMapping
  where
    doOpen           = createFile (filePathToLString path) gENERIC_READ fILE_SHARE_READ Nothing oPEN_EXISTING fILE_ATTRIBUTE_NORMAL Nothing
    doMapping handle = bracket (createFileMapping (Just handle) pAGE_READONLY 0 Nothing)
                               closeHandle
                               (getSizeAndMap handle)
    getSizeAndMap handle filemap = do
        fileInfo <- getFileInformationByHandle handle
        mask_ $ do
            ptr <- mapViewOfFile filemap fILE_MAP_READ 0 0
            return $ FileMapping ptr (FileSize $ bhfiSize fileInfo) (unmapViewOfFile ptr)