on master help sign in
added a few instances
commitcebcaa22c7f60015c80e9d555a1c67ab235c6638 authoraslatter <aslatter@gmail.com> dateSun 23 Mar 2008, 07:23 (19 years ago) parentd7f3dcc
2 files changed+27−4
Data/UUID.hs+25 uuid.cabal+2−4
Data/UUID.hs+25
@@ -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 ()
uuid.cabal+2−4
@@ -15,6 +15,7 @@ Description:
1515 The library libuuid is available as a part of e2fsprogs:
1616 <http://e2fsprogs.sourceforge.net/>.
1717
18+
1819 This library is useful for creating, comparing, parsing and
1920 printing Universally Unique Identifiers.
2021 See <http://en.wikipedia.org/wiki/UUID> for the general idea.
@@ -28,7 +29,4 @@ Library
2829
2930 Extensions: ForeignFunctionInterface
3031
31− Extra-Libraries: uuid
32−
33−
34−
32+ Extra-Libraries: uuid