[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36
John Goerzen
jgoerzen at complete.org
Fri Apr 23 15:02:56 UTC 2010
The following commit has been merged in the master branch:
commit 5a8c3b1ce4b9a46748e8027d6ebd298ba4ffe69f
Author: John Goerzen <jgoerzen at complete.org>
Date: Mon Oct 10 07:12:58 2005 +0100
Initial support to expand past String for I/O
diff --git a/MissingH/IO/Binary.hs b/MissingH/IO/Binary.hs
index 073aaa0..f537bc0 100644
--- a/MissingH/IO/Binary.hs
+++ b/MissingH/IO/Binary.hs
@@ -68,9 +68,29 @@ module MissingH.IO.Binary(-- * Entire File\/Handle Utilities
import Foreign.Ptr
import Foreign.ForeignPtr
import Foreign.C.String
+import Foreign.C.Types
+import Foreign.Marshal.Array
+import Data.Word
import System.IO.Unsafe
import System.IO
+class BinaryConvertable a where
+ toBuf :: a -> (Ptr CChar -> IO c) -> IO c
+ fromBuf :: Int -> (Ptr CChar -> IO a) -> IO a
+
+instance BinaryConvertable String where
+ toBuf = withCString
+ fromBuf len func =
+ do fbuf <- mallocForeignPtrArray (len + 1)
+ withForeignPtr fbuf func
+
+instance BinaryConvertable [Word8] where
+ toBuf hslist func = withArray hslist (\ptr -> func (castPtr ptr))
+ fromBuf len func =
+ do (fbuf::(ForeignPtr Word8)) <- mallocForeignPtrArray (len + 1)
+ withForeignPtr fbuf (\ptr -> func (castPtr ptr))
+
+
-- . **************************************************
-- . Binary Files
-- . **************************************************
--
haskell-testpack
More information about the Pkg-haskell-commits
mailing list