From 7ad3fd1f6fe3c6719b69f3638542f24b32a3b09c Mon Sep 17 00:00:00 2001 From: Sam T Date: Tue, 16 Jul 2013 07:47:28 +0400 Subject: + Add posix-like file interface. --- src/System/IO/MMap/Fixed.hs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/System/IO') diff --git a/src/System/IO/MMap/Fixed.hs b/src/System/IO/MMap/Fixed.hs index 9d2e354f..df6a6603 100644 --- a/src/System/IO/MMap/Fixed.hs +++ b/src/System/IO/MMap/Fixed.hs @@ -46,6 +46,7 @@ -- > http://hackage.haskell.org/package/mmap -- > man mmap -- +{-# LANGUAGE RecordWildCards #-} module System.IO.MMap.Fixed ( -- * Intervals FixedOffset, FileOffset, FixedInterval, FileInterval @@ -58,6 +59,7 @@ module System.IO.MMap.Fixed -- ** Specialized 'insertTo' , mmapTo, mallocTo + , lookupRegion -- * Query , upperAddr @@ -146,6 +148,13 @@ mallocTo fi s = do fptr <- mallocForeignPtrBytes bsize return (insertTo fi (fptr, 0) s) +lookupRegion :: FixedOffset -> Fixed -> Maybe B.ByteString +lookupRegion offset Fixed {..} = + case intersecting imap $ IntervalCO offset (succ offset) of + [(i, (fptr, off))] -> let s = max 0 $ upperBound i - lowerBound i + in Just $ fromForeignPtr fptr off s + _ -> Nothing + -- | Note: this is unsafe operation. viewBytes :: FixedInterval -> Fixed -> Lazy.ByteString viewBytes fi s = fromChunks $ L.map mk $ (imap s `intersecting` fi) -- cgit v1.2.3