summaryrefslogtreecommitdiff
path: root/DotLock.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2013-12-02 16:21:15 -0500
committerjoe <joe@jerkface.net>2013-12-02 16:21:15 -0500
commitfc3c9169126867bc0884a28b36e95469a3a2ef3b (patch)
tree7901b5b1c37cbe4cb9fbfd4a72cadd14c9cea4b8 /DotLock.hs
parentab12445390b5861ce1865dabd78de8d8fc08581d (diff)
dotlock bindings.
Diffstat (limited to 'DotLock.hs')
-rw-r--r--DotLock.hs44
1 files changed, 44 insertions, 0 deletions
diff --git a/DotLock.hs b/DotLock.hs
new file mode 100644
index 0000000..257a033
--- /dev/null
+++ b/DotLock.hs
@@ -0,0 +1,44 @@
1module DotLock
2 ( DotLock
3 , Flags
4 , dotlock_init
5 , dotlock_create
6 , dotlock_take
7 , dotlock_release
8 , dotlock_destroy
9 , dotlock_remove_lockfiles
10 , dotlock_set_fd
11 , dotlock_get_fd
12 , dotlock_disable
13 ) where
14
15import System.Posix.Types (Fd(..))
16import Foreign.C.String
17import Foreign.C.Types
18import Foreign.Ptr
19
20newtype DotLock = DotLockPtr (Ptr ())
21type Flags = Int
22
23foreign import ccall "dotlock_create" _dotlock_create_ptr :: Ptr Char -> Flags -> IO (Ptr ())
24
25foreign import ccall "dotlock_create" _dotlock_create :: CString -> Flags -> IO (Ptr ())
26
27dotlock_init :: IO ()
28dotlock_init = do
29 null_ptr <- _dotlock_create_ptr nullPtr 0
30 return ()
31
32dotlock_create :: FilePath -> Flags -> IO (Maybe DotLock)
33dotlock_create file flags = do
34 ptr <- withCString file (flip _dotlock_create flags)
35 if ptr == nullPtr then return Nothing else return (Just $ DotLockPtr ptr)
36
37
38foreign import ccall "dotlock_take" dotlock_take :: DotLock -> CLong -> IO CInt
39foreign import ccall "dotlock_release" dotlock_release :: DotLock -> IO CInt
40foreign import ccall "dotlock_destroy" dotlock_destroy :: DotLock -> IO ()
41foreign import ccall "dotlock_remove_lockfiles" dotlock_remove_lockfiles ::DotLock -> IO ()
42foreign import ccall "dotlock_set_fd" dotlock_set_fd :: DotLock -> Fd -> IO ()
43foreign import ccall "dotlock_get_fd" dotlock_get_fd :: DotLock -> IO Fd
44foreign import ccall "dotlock_disable" dotlock_disable :: IO ()