packages feed

uuid 0.1.0 → 0.1.1

raw patch · 4 files changed

+41/−38 lines, 4 files

Files

+ CONTRIBUTORS view
@@ -0,0 +1,4 @@+In order of appearance:++Antoine Latter+Jason Dusek
Data/UUID.hs view
@@ -95,25 +95,22 @@ -- Otherwise a UUID will be generated based on the current time and the -- hardware MAC address, if available. generate :: IO UUID-generate = do-  fp <- mallocForeignPtrArray 16-  withForeignPtr fp $ \p -> c_generate p-  return $ U fp+generate = generateWrap c_generate  -- |Create a new 'UUID'.  If \/dev\/urandom is available, it will be used. -- Otherwise a psuedorandom generator will be used. generateRandom :: IO UUID-generateRandom = do-  fp <- mallocForeignPtrArray 16-  withForeignPtr fp $ \p -> c_generate_random p-  return $ U fp+generateRandom = generateWrap c_generate_random  -- |Create a new 'UUID'.  The UUID will be  generated based on the -- current time and the hardware MAC address, if available. generateTime :: IO UUID-generateTime = do +generateTime = generateWrap c_generate_time++generateWrap :: (C_UUID -> IO ()) -> IO UUID+generateWrap gen = do   fp <- mallocForeignPtrArray 16-  withForeignPtr fp $ \p -> c_generate_time p+  withForeignPtr fp $ \p -> gen p   return $ U fp  -- |Returns 'True' if the passed-in 'UUID' is the null UUID.@@ -136,7 +133,7 @@   fp <- mallocForeignPtrArray 16   res <- withCAString s $ \chars ->       withForeignPtr fp $ \p ->-      c_read (castPtr chars) p+      c_read chars p   case res of     0 -> return . Just $ U fp     _ -> return Nothing@@ -145,33 +142,27 @@ -- Hex digits occuring in the output will be either upper or -- lower-case depending on system defaults and locale. toString :: UUID -> String-toString (U fp) = unsafePerformIO $ do-  chars <- mallocBytes 37-  withForeignPtr fp $ \p -> c_show p chars-  st <- peekCAString chars-  free chars-  return st+toString = toStringWrap c_show  -- |Returns a 'String' representation of the passed in 'UUID'. -- Hex digits occuring in the output will be lower-case. toStringLower :: UUID -> String-toStringLower (U fp) = unsafePerformIO $ do-  chars <- mallocBytes 37-  withForeignPtr fp $ \p -> c_show_lower p chars-  st <- peekCAString chars-  free chars-  return st+toStringLower = toStringWrap c_show_lower    -- |Returns a 'String' representation of the passed in 'UUID'. -- Hex digits occuring in the output will be upper-case. toStringUpper :: UUID -> String-toStringUpper (U fp) = unsafePerformIO $ do-  chars <- mallocBytes 37-  withForeignPtr fp $ \p -> c_show_upper p chars-  st <- peekCAString chars-  free chars-  return st+toStringUpper = toStringWrap c_show_upper +-- |The passed in function /f/ is given a the raw UUID data+-- and a 37-byte buffer to fill with the textual representation+-- of the UUID.  The buffer is expected to contain a null-terminator+-- after /f/ is finished.+toStringWrap :: (C_UUID -> CString -> IO ()) -> UUID -> String+toStringWrap f (U fp) = unsafePerformIO $+  allocaBytes 37 $ \chars -> do+  withForeignPtr fp $ \p -> f p chars+  peekCAString chars  -- FFI calls to do the work 
Data/UUID/Internal.hs view
@@ -40,7 +40,7 @@  else error "Data.UUID.Internal.fromBytes: passed in list of bytes must be of length 16."  -- |Creates a UUID out of a list of bytes.--- Does not perform a length check.+-- Does not perform a length check on the passed in list. -- Behavior is undefined for lists not of length 16. unsafeFromBytes :: [Word8] -> UUID unsafeFromBytes xs = U $ castForeignPtr $ unsafePerformIO $ do@@ -48,12 +48,16 @@    withForeignPtr p $ flip pokeArray xs    return p --- |Given a UUID, returns a pointer to the 16 bytes+-- |Unsafe.+--+-- Given a UUID, returns a pointer to the 16 bytes -- of memory that make up the UUID. toForeignPtr :: UUID -> ForeignPtr CChar toForeignPtr (U p) = p --- |The passed in pointer is treated as if it were a pointer--- to 16 bytes of memory.  You're in trouble if it isn't.+-- |Unsafe.+--+-- The passed in pointer is treated as if it were a pointer+-- to 16 bytes of memory, which is then returned as a UUID. fromForeignPtr :: ForeignPtr CChar -> UUID fromForeignPtr = U
uuid.cabal view
@@ -1,6 +1,6 @@ Name: uuid-Version: 0.1.0-Copyright: 2008, Antoine Latter+Version: 0.1.1+Copyright: (c) 2008 Antoine Latter Author: Antoine Latter Maintainer: aslatter@gmail.com License: BSD3@@ -12,14 +12,17 @@  Description:  Haskell bindings to libuuid.+ .  The library libuuid is available as a part of e2fsprogs:  <http://e2fsprogs.sourceforge.net/>.--+ .+ .  This library is useful for creating, comparing, parsing and  printing Universally Unique Identifiers.  See <http://en.wikipedia.org/wiki/UUID> for the general idea.  +Synopsis: For creating, comparing, parsing and printing Universally Unique Identifiers+ Library  Build-Depends: base @@ -29,4 +32,5 @@   Extensions: ForeignFunctionInterface - Extra-Libraries: uuid+ if !os(darwin)+  Extra-Libraries: uuid