diff options
Diffstat (limited to 'Inotify.icl')
-rw-r--r-- | Inotify.icl | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/Inotify.icl b/Inotify.icl index d25a426..62d4bfd 100644 --- a/Inotify.icl +++ b/Inotify.icl @@ -1,24 +1,26 @@ implementation module Inotify -import Data.Either -import Data.List -import Data.Maybe - import StdArray import StdBool import StdFunc import StdInt import StdList +from StdOverloaded import class zero(zero) import StdString -from StdOverloaded import class zero(zero) +import Data.Either +import Data.List +import Data.Maybe +import System._Pointer +import System._Posix import code from "inotify_c.o" -:: *Inotify st = { fd :: *Int - , watches :: [(INWatch, INCallback st)] - , state :: st - } +:: *Inotify st = + { fd :: !Int + , watches :: ![(INWatch, INCallback st)] + , state :: !st + } :: INWatch :== Int @@ -27,17 +29,21 @@ import code from "inotify_c.o" inotify_init :: st -> Maybe *(Inotify st) inotify_init st - = let fd=c_init 0 in if (fd<0) Nothing (Just {fd=fd, watches=[], state=st}) + # (fd,_) = c_init 0 + | fd < 0 = Nothing + # (i,_) = fcntlArg fd 00004000 0 37 // IN_NONBLOCK + | i <> i = Nothing + = Just {fd=fd, watches=[], state=st} where - c_init :: !Int -> *Int + c_init :: !Int -> (!Int, !Int) c_init i = code { - ccall clean_inotify_init "I:I" + ccall inotify_init ":I:I" } inotify_close :: *(Inotify st) -> st inotify_close {fd,state} = c_close fd state where - c_close :: !*Int !st -> st + c_close :: !Int !st -> st c_close fd st = code { ccall close "I:V:A" } @@ -45,24 +51,26 @@ where inotify_add_watch :: (INCallback st) !INMask !String !*(Inotify st) -> *(!Either Int INWatch, !*Inotify st) inotify_add_watch f mask fname inot=:{fd,watches} - = let (w, fd`) = c_add_watch fd fname mask in - ( if (w == -1) (Left errno) (Right w) - , {inot & fd=fd`, watches=[(w,f):watches]} - ) + # w = c_add_watch fd (packString fname) mask + | w == -1 + # (err,inot) = errno inot + = (Left err,inot) + = (Right w, {inot & watches=[(w,f):watches]}) where - c_add_watch :: !*Int !String !Int -> *(!Int, !*Int) + c_add_watch :: !Int !String !Int -> Int c_add_watch inot fname mask = code { - ccall clean_inotify_add_watch "ISI:VII" + ccall inotify_add_watch "IsI:I" } inotify_rm_watch :: !INWatch !*(Inotify st) -> *(!Bool, !*Inotify st) inotify_rm_watch w inot=:{fd} - = case c_inotify_rm_watch fd w of (0, fd`) = (True, {inot & fd=fd`}) - (_, fd`) = (False, {inot & fd=fd`}) + = case c_inotify_rm_watch fd w of + 0 -> (True, inot) + _ -> (False, inot) where - c_inotify_rm_watch :: !*Int !Int -> *(!Int, !*Int) + c_inotify_rm_watch :: !Int !Int -> Int c_inotify_rm_watch w i = code { - ccall clean_inotify_rm_watch "II:VII" + ccall inotify_rm_watch "II:I" } inotify_poll :: !(Maybe Int) !*(Inotify st) -> *(!Int, !*Inotify st) @@ -70,7 +78,7 @@ inotify_poll mbTo inot=:{fd} = let (n,fd`)=c_poll fd to in (n, {inot & fd=fd`}) where to = if (isNothing mbTo) -1 (fromJust mbTo) - c_poll :: !*Int !Int -> *(!Int, !*Int) + c_poll :: !Int !Int -> (!Int, !Int) c_poll fd timeout = code { ccall clean_poll "II:VII" } @@ -87,8 +95,8 @@ inotify_check inot=:{fd,watches,state} w # (fd,st,w`) = seq (map (check infos) watches) (inot.fd, state, w) = ({ inot & fd=fd, state=st }, w`) where - check :: [(Int,Int,String)] (INWatch, INCallback st) *(*Int, st, *World) - -> *(*Int, st, *World) + check :: [(Int,Int,String)] (INWatch, INCallback st) *(Int, st, *World) + -> *(Int, st, *World) check infos (watch,f) (fd,st,w) # (st,w) = seq [\(st,w) -> f mask (toMaybe name) st w \\ (wd,mask,name) <- infos | wd == watch] (st,w) @@ -114,7 +122,7 @@ where split` c cs=:[x:xs] = let (l,r) = span ((<>)c) cs in [l:split` c (removeMember c r)] - c_check :: !*Int -> *(!Bool, !String, !String, !String, !*Int) + c_check :: !Int -> (!Bool, !String, !String, !String, !Int) c_check fd = code { ccall clean_inotify_check "I:VISSSI" } @@ -132,11 +140,3 @@ inotify_loop_with_timeout to inot w inotify_loop_forever :: !*(Inotify st) !*World -> *(!*Inotify st, !*World) inotify_loop_forever inot w = inotify_loop_with_timeout Nothing inot w - -errno :: Int -errno = err 0 -where - err :: !Int -> Int - err i = code { - ccall clean_errno "I:I" - } |