{-# LINE 1 "System\\Win32\\WindowsString\\FileMapping.hsc" #-}-----------------------------------------------------------------------------
-- |
-- Module : System.Win32.FileMapping
-- Copyright : (c) Esa Ilari Vuokko, 2006
-- License : BSD-style (see the file LICENSE)
--
-- Maintainer : Esa Ilari Vuokko <ei@vuokko.info>
-- Stability : provisional
-- Portability : portable
--
-- A collection of FFI declarations for interfacing with Win32 mapped files.
--
-----------------------------------------------------------------------------
moduleSystem.Win32.WindowsString.FileMapping(moduleSystem.Win32.WindowsString.FileMapping,moduleSystem.Win32.FileMapping)whereimportSystem.Win32.FileMappinghiding(mapFile,withMappedFile,createFileMapping,openFileMapping)importSystem.Win32.FileMapping.InternalimportSystem.Win32.WindowsString.Types(HANDLE,BOOL,withTString,failIf,DDWORD,ddwordToDwords,iNVALID_HANDLE_VALUE)importSystem.Win32.MemimportSystem.Win32.WindowsString.FileimportSystem.OsString.WindowsimportSystem.OsPath.WindowsimportControl.Exception(mask_,bracket)importForeign(nullPtr,maybeWith,ForeignPtr,newForeignPtr)
#include "windows_cconv.h"
---------------------------------------------------------------------------
-- Derived functions
---------------------------------------------------------------------------
-- | Maps file fully and returns ForeignPtr and length of the mapped area.
-- The mapped file is opened read-only and shared reading.
mapFile::WindowsPath->IO(ForeignPtra,Int)mapFilepath=dobracket(createFilepathgENERIC_READfILE_SHARE_READNothingoPEN_EXISTINGfILE_ATTRIBUTE_NORMALNothing)(closeHandle)$\fh->bracket(createFileMapping(Justfh)pAGE_READONLY0Nothing)(closeHandle)$\fm->dofi<-getFileInformationByHandlefhfp<-mask_$doptr<-mapViewOfFilefmfILE_MAP_READ00newForeignPtrc_UnmapViewOfFileFinaliserptrreturn(fp,fromIntegral$bhfiSizefi)-- | Opens an existing file and creates mapping object to it.
withMappedFile::WindowsPath-- ^ Path
->Bool-- ^ Write? (False = read-only)
->MaybeBool-- ^ Sharing mode, no sharing, share read, share read+write
->(Integer->MappedObject->IOa)-- ^ Action
->IOawithMappedFilepathwriteshareact=bracket(createFilepathaccessshare'NothingoPEN_EXISTINGfILE_ATTRIBUTE_NORMALNothing)(closeHandle)$\fh->bracket(createFileMapping(Justfh)page0Nothing)(closeHandle)$\fm->dobhfi<-getFileInformationByHandlefhact(fromIntegral$bhfiSizebhfi)(MappedObjectfhfmmapaccess)whereaccess=ifwritethengENERIC_READ+gENERIC_WRITEelsegENERIC_READpage=ifwritethenpAGE_READWRITEelsepAGE_READONLYmapaccess=ifwritethenfILE_MAP_ALL_ACCESSelsefILE_MAP_READshare'=caseshareofNothing->fILE_SHARE_NONEJustFalse->fILE_SHARE_READJustTrue->fILE_SHARE_READ+fILE_SHARE_WRITE---------------------------------------------------------------------------
-- API in Haskell
---------------------------------------------------------------------------
createFileMapping::MaybeHANDLE->ProtectFlags->DDWORD->MaybeWindowsString->IOHANDLEcreateFileMappingmhflagsmosizename=maybeWithwithTStringname$\c_name->failIf(==nullPtr)"createFileMapping: CreateFileMapping"$c_CreateFileMappinghandlenullPtrflagsmoshimoslowc_namewhere(moshi,moslow)=ddwordToDwordsmosizehandle=maybeiNVALID_HANDLE_VALUEidmhopenFileMapping::FileMapAccess->BOOL->MaybeWindowsString->IOHANDLEopenFileMappingaccessinheritname=maybeWithwithTStringname$\c_name->failIf(==nullPtr)"openFileMapping: OpenFileMapping"$c_OpenFileMappingaccessinheritc_name

AltStyle によって変換されたページ (->オリジナル) /