module System.Posix.Types ( CDev(..), CIno(..), CMode(..), COff(..), CPid(..), CSsize(..), CGid(..), CNlink(..), CUid(..), CCc(..), CSpeed(..), CTcflag(..), CRLim(..), CBlkSize(..), CBlkCnt(..), CClockId(..), CFsBlkCnt(..), CFsFilCnt(..), CId(..), CKey(..), CTimer(..), CSocklen(..), CNfds(..), Fd(..), LinkCount, UserID, GroupID, ByteCount, ClockTick, EpochTime, FileOffset, ProcessID, ProcessGroupID, DeviceID, FileID, FileMode, Limit ) whereimport Data.Bitsimport Data.Intimport Data.Iximport Data.Wordimport Foreign.C.Typesimport Foreign.Ptrimport Foreign.Storable-- The types are highly platform dependent.-- What we have here should work on-- Linux 64 bit-- Linux 32 bit-- MacOS 64 bit-- The actual size of the representation type is >= the platform type,-- but the storable instance has the right size.toI32 :: Integral a => a -> Int32toI32 = fromIntegralfromI32 :: Integral a => Int32 -> afromI32 = fromIntegraltoU32 :: Integral a => a -> Word32toU32 = fromIntegralfromU32 :: Integral a => Word32 -> afromU32 = fromIntegraltoU16 :: Integral a => a -> Word16toU16 = fromIntegralfromU16 :: Integral a => Word16 -> afromU16 = fromIntegralnewtype CDev = CDev Word64 deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord)instance Storable CDev where sizeOf (CDev x) = if _isMacOS then sizeOf (toI32 x) else sizeOf x alignment (CDev x) = if _isMacOS then alignment (toI32 x) else alignment x peek p = CDev <$> if _isMacOS then fromI32 <$> peek (castPtr p) else peek (castPtr p) poke p (CDev x) = if _isMacOS then poke (castPtr p) (toI32 x) else poke (castPtr p) xnewtype CIno = CIno Word64 deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord, Storable)newtype CMode = CMode Word32 deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord, Storable)newtype COff = COff Int64 deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord, Storable)newtype CPid = CPid Int32 deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord, Storable)newtype CSsize = CSsize Int deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord, Storable)newtype CGid = CGid Word32 deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord, Storable)newtype CNlink = CNlink Word deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord)instance Storable CNlink where sizeOf (CNlink x) = if _isMacOS then sizeOf (toU16 x) else sizeOf x alignment (CNlink x) = if _isMacOS then alignment (toU16 x) else alignment x peek p = CNlink <$> if _isMacOS then fromU16 <$> peek (castPtr p) else peek (castPtr p) poke p (CNlink x) = if _isMacOS then poke (castPtr p) (toU16 x) else poke (castPtr p) xnewtype CUid = CUid Word32 deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord, Storable)newtype CCc = CCc Word8 deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord, Storable)newtype CSpeed = CSpeed Word64 deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord)instance Storable CSpeed where sizeOf (CSpeed x) = if not _isMacOS then sizeOf (toU32 x) else sizeOf x alignment (CSpeed x) = if not _isMacOS then alignment (toU32 x) else alignment x peek p = CSpeed <$> if not _isMacOS then fromU32 <$> peek (castPtr p) else peek (castPtr p) poke p (CSpeed x) = if not _isMacOS then poke (castPtr p) (toU32 x) else poke (castPtr p) xnewtype CTcflag = CTcflag Word64 deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord)instance Storable CTcflag where sizeOf (CTcflag x) = if not _isMacOS then sizeOf (toU32 x) else sizeOf x alignment (CTcflag x) = if not _isMacOS then alignment (toU32 x) else alignment x peek p = CTcflag <$> if not _isMacOS then fromU32 <$> peek (castPtr p) else peek (castPtr p) poke p (CTcflag x) = if not _isMacOS then poke (castPtr p) (toU32 x) else poke (castPtr p) xnewtype CRLim = CRLim Word64 deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord, Storable)newtype CBlkSize = CBlkSize Word deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord)instance Storable CBlkSize where sizeOf (CBlkSize x) = if _isMacOS then sizeOf (toI32 x) else sizeOf x alignment (CBlkSize x) = if _isMacOS then alignment (toI32 x) else alignment x peek p = CBlkSize <$> if _isMacOS then fromI32 <$> peek (castPtr p) else peek (castPtr p) poke p (CBlkSize x) = if _isMacOS then poke (castPtr p) (toI32 x) else poke (castPtr p) xnewtype CBlkCnt = CBlkCnt Word64 deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord, Storable)newtype CClockId = CClockId Int deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord, Storable)newtype CFsBlkCnt = CFsBlkCnt Word64 deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord, Storable)newtype CFsFilCnt = CFsFilCnt Word64 deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord, Storable)newtype CId = CId Int deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord, Storable)newtype CKey = CKey Int deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord, Storable)newtype CTimer = CTimer Word deriving (Show, Eq, Ord, Storable)newtype CSocklen = CSocklen Word32 deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord, Storable)newtype CNfds = CNfds Word64 deriving (Bits, FiniteBits, Bounded, Enum, Ix, Num, Read, Integral, Real, Show, Eq, Ord)instance Storable CNfds where sizeOf (CNfds x) = if _isMacOS then sizeOf (toI32 x) else sizeOf x alignment (CNfds x) = if _isMacOS then alignment (toI32 x) else alignment x peek p = CNfds <$> if _isMacOS then fromI32 <$> peek (castPtr p) else peek (castPtr p) poke p (CNfds x) = if _isMacOS then poke (castPtr p) (toI32 x) else poke (castPtr p) xnewtype Fd = Fd CInt deriving (Bits, FiniteBits, Bounded, Enum, {-Ix,-} Num, {-Read,-} Integral, Real, Show, Eq, Ord, Storable)type LinkCount = CNlinktype UserID = CUidtype GroupID = CGidtype ByteCount = CSizetype ClockTick = CClocktype EpochTime = CTimetype DeviceID = CDevtype FileID = CInotype FileMode = CModetype ProcessID = CPidtype FileOffset = COfftype ProcessGroupID = CPidtype Limit = CLong