diff options
Diffstat (limited to 'DotLock.hs')
-rw-r--r-- | DotLock.hs | 44 |
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 @@ | |||
1 | module 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 | |||
15 | import System.Posix.Types (Fd(..)) | ||
16 | import Foreign.C.String | ||
17 | import Foreign.C.Types | ||
18 | import Foreign.Ptr | ||
19 | |||
20 | newtype DotLock = DotLockPtr (Ptr ()) | ||
21 | type Flags = Int | ||
22 | |||
23 | foreign import ccall "dotlock_create" _dotlock_create_ptr :: Ptr Char -> Flags -> IO (Ptr ()) | ||
24 | |||
25 | foreign import ccall "dotlock_create" _dotlock_create :: CString -> Flags -> IO (Ptr ()) | ||
26 | |||
27 | dotlock_init :: IO () | ||
28 | dotlock_init = do | ||
29 | null_ptr <- _dotlock_create_ptr nullPtr 0 | ||
30 | return () | ||
31 | |||
32 | dotlock_create :: FilePath -> Flags -> IO (Maybe DotLock) | ||
33 | dotlock_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 | |||
38 | foreign import ccall "dotlock_take" dotlock_take :: DotLock -> CLong -> IO CInt | ||
39 | foreign import ccall "dotlock_release" dotlock_release :: DotLock -> IO CInt | ||
40 | foreign import ccall "dotlock_destroy" dotlock_destroy :: DotLock -> IO () | ||
41 | foreign import ccall "dotlock_remove_lockfiles" dotlock_remove_lockfiles ::DotLock -> IO () | ||
42 | foreign import ccall "dotlock_set_fd" dotlock_set_fd :: DotLock -> Fd -> IO () | ||
43 | foreign import ccall "dotlock_get_fd" dotlock_get_fd :: DotLock -> IO Fd | ||
44 | foreign import ccall "dotlock_disable" dotlock_disable :: IO () | ||