@@ -1,4 +1,5 @@
11{-# INCLUDE <uuid/uuid.h> #-}
2+{-# INCLUDE <string.h> #-}
23{-# LANGUAGE ForeignFunctionInterface #-}
34
45-- |Haskell bindings to /libuuid/.
@@ -26,6 +27,8 @@ import Foreign.C
2627import Foreign.ForeignPtr
2728import Foreign
2829
30+import Data.Typeable
31+
2932import Prelude hiding (null)
3033
3134import Data.UUID.Internal
@@ -50,6 +53,23 @@ instance Read UUID where
5053 Nothing -> []
5154 Just u -> [(u,drop 36 str)]
5255
56+instance Typeable UUID where
57+ typeOf _ = mkTyConApp (mkTyCon "Data.UUID.UUID") []
58+
59+instance Storable UUID where
60+ sizeOf _ = (16 *) $ alignment (undefined :: CChar)
61+ alignment _ = alignment (undefined :: CChar)
62+
63+ peek psource = do
64+ fp <- mallocForeignPtrArray 16
65+ withForeignPtr fp $ \pdest ->
66+ memcpy pdest psource $ fromIntegral $ sizeOf (undefined :: UUID)
67+ return $ U fp
68+
69+ poke pdest (U fp) = withForeignPtr fp $ \psource ->
70+ memcpy pdest psource $ fromIntegral $ sizeOf (undefined :: UUID)
71+
72+
5373-- |Creates a new 'UUID'. If \/dev\/urandom is available, it will be used.
5474-- Otherwise a UUID will be generated based on the current time and the
5575-- hardware MAC address, if available.
@@ -177,3 +197,8 @@ foreign import ccall unsafe "uuid_type"
177197
178198foreign import ccall unsafe "uuid_variant"
179199 c_variant :: C_UUID -> CInt
200+
201+-- Other
202+
203+foreign import ccall unsafe "memcpy"
204+ memcpy :: Ptr a -> Ptr b -> CSize -> IO ()