From fc3c9169126867bc0884a28b36e95469a3a2ef3b Mon Sep 17 00:00:00 2001 From: joe Date: Mon, 2 Dec 2013 16:21:15 -0500 Subject: dotlock bindings. --- DotLock.hs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 DotLock.hs (limited to 'DotLock.hs') diff --git a/DotLock.hs b/DotLock.hs new file mode 100644 index 0000000..257a033 --- /dev/null +++ b/DotLock.hs @@ -0,0 +1,44 @@ +module DotLock + ( DotLock + , Flags + , dotlock_init + , dotlock_create + , dotlock_take + , dotlock_release + , dotlock_destroy + , dotlock_remove_lockfiles + , dotlock_set_fd + , dotlock_get_fd + , dotlock_disable + ) where + +import System.Posix.Types (Fd(..)) +import Foreign.C.String +import Foreign.C.Types +import Foreign.Ptr + +newtype DotLock = DotLockPtr (Ptr ()) +type Flags = Int + +foreign import ccall "dotlock_create" _dotlock_create_ptr :: Ptr Char -> Flags -> IO (Ptr ()) + +foreign import ccall "dotlock_create" _dotlock_create :: CString -> Flags -> IO (Ptr ()) + +dotlock_init :: IO () +dotlock_init = do + null_ptr <- _dotlock_create_ptr nullPtr 0 + return () + +dotlock_create :: FilePath -> Flags -> IO (Maybe DotLock) +dotlock_create file flags = do + ptr <- withCString file (flip _dotlock_create flags) + if ptr == nullPtr then return Nothing else return (Just $ DotLockPtr ptr) + + +foreign import ccall "dotlock_take" dotlock_take :: DotLock -> CLong -> IO CInt +foreign import ccall "dotlock_release" dotlock_release :: DotLock -> IO CInt +foreign import ccall "dotlock_destroy" dotlock_destroy :: DotLock -> IO () +foreign import ccall "dotlock_remove_lockfiles" dotlock_remove_lockfiles ::DotLock -> IO () +foreign import ccall "dotlock_set_fd" dotlock_set_fd :: DotLock -> Fd -> IO () +foreign import ccall "dotlock_get_fd" dotlock_get_fd :: DotLock -> IO Fd +foreign import ccall "dotlock_disable" dotlock_disable :: IO () -- cgit v1.2.3