PageRenderTime 25ms CodeModel.GetById 22ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Flock.hsc

http://github.com/Eelis/geordi
Unknown | 16 lines | 11 code | 5 blank | 0 comment | 0 complexity | 336a034f76c6af85ee67663637f0b9ac MD5 | raw file
 1{-# LANGUAGE UnicodeSyntax, ForeignFunctionInterface #-}
 2module Flock (exclusive) where
 3
 4import System.Posix.Types
 5import Foreign.C
 6import Prelude (IO, ($))
 7
 8#include <sys/file.h>
 9
10foreign import ccall unsafe "flock" c_flock :: CInt ? CInt ? IO CInt
11
12flock :: CInt ? CInt ? IO ()
13flock fd op = throwErrnoIfMinus1_ "flock" $ c_flock fd op
14
15exclusive :: Fd ? IO ()
16exclusive (Fd fd) = flock fd (#const LOCK_EX)