module System.Posix.Syslog.LogMask where
import System.Posix.Syslog.Functions ( _logMask )
import System.Posix.Syslog.Priority ( Priority, fromPriority )
import Data.Bits
import Foreign.C.Types
toLogMask :: [Priority] -> CInt
toLogMask :: [Priority] -> CInt
toLogMask = (Priority -> CInt -> CInt) -> CInt -> [Priority] -> CInt
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (CInt -> CInt -> CInt
forall a. Bits a => a -> a -> a
(.|.) (CInt -> CInt -> CInt)
-> (Priority -> CInt) -> Priority -> CInt -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CInt -> CInt
_logMask (CInt -> CInt) -> (Priority -> CInt) -> Priority -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Priority -> CInt
fromPriority) CInt
0
fromLogMask :: CInt -> [Priority]
fromLogMask :: CInt -> [Priority]
fromLogMask CInt
old = [ Priority
p | Priority
p <- [Priority
forall a. Bounded a => a
minBound..Priority
forall a. Bounded a => a
maxBound], CInt -> CInt
_logMask (Priority -> CInt
fromPriority Priority
p) CInt -> CInt -> CInt
forall a. Bits a => a -> a -> a
.&. CInt
old CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0 ]