64c3e28aca1ddf15719eed6ef763d68967fc6bb6
[ghc-base.git] / NHC / PosixTypes.hsc
1 {-# OPTIONS_NHC98 -I/usr/include #-}
2 -----------------------------------------------------------------------------
3 -- |
4 -- Module      :  NHC.PosixTypes
5 -- Copyright   :  (c) Malcolm Wallace 2007
6 -- License     :  BSD-style (see the file libraries/base/LICENSE)
7 -- 
8 -- Maintainer  :  libraries@haskell.org
9 -- Stability   :  provisional
10 -- Portability :  non-portable (requires POSIX)
11 --
12 -- POSIX data types: Haskell equivalents of the types defined by the
13 -- @\<sys\/types.h>@ C header on a POSIX system.
14 --
15 -----------------------------------------------------------------------------
16
17 module NHC.PosixTypes (
18
19   -- * POSIX data types
20   CDev,
21   CIno,
22   CMode,
23   COff,
24   CPid,
25   CSsize,
26
27   CGid,
28   CNlink,
29   CUid,
30   CCc,
31   CSpeed,
32   CTcflag,
33   CRLim,
34
35   Fd(..),
36
37   LinkCount,
38   UserID,
39   GroupID,
40  ) where
41
42 import Foreign
43 import Foreign.C
44 import Data.Typeable
45 import Data.Bits
46 import Unsafe.Coerce
47
48 import Control.Monad
49
50
51 -- Curious hack to ensure that the CTypes macros are expanded *after* hsc2hs.
52 ##include "CTypes.h"
53 -- C header files that contain all the types we are looking for here.
54 #if __APPLE__
55 #include <libc.h>
56 #endif
57 #include <stdlib.h>
58 #include <unistd.h>
59 #include <sys/resource.h>
60 #include <termios.h>
61
62 ARITHMETIC_TYPE(CDev,tyConCDev,"CDev",#{type dev_t})
63 INTEGRAL_TYPE(CIno,tyConCIno,"CIno",#{type ino_t})
64 INTEGRAL_TYPE(CMode,tyConCMode,"CMode",#{type mode_t})
65 INTEGRAL_TYPE(COff,tyConCOff,"COff",#{type off_t})
66 INTEGRAL_TYPE(CPid,tyConCPid,"CPid",#{type pid_t})
67
68 INTEGRAL_TYPE(CSsize,tyConCSsize,"CSsize",#{type ssize_t})
69
70 INTEGRAL_TYPE(CGid,tyConCGid,"CGid",#{type gid_t})
71 INTEGRAL_TYPE(CNlink,tyConCNlink,"CNlink",#{type nlink_t})
72
73 INTEGRAL_TYPE(CUid,tyConCUid,"CUid",#{type uid_t})
74 ARITHMETIC_TYPE(CCc,tyConCCc,"CCc",#{type cc_t})
75 ARITHMETIC_TYPE(CSpeed,tyConCSpeed,"CSpeed",#{type speed_t})
76 INTEGRAL_TYPE(CTcflag,tyConCTcflag,"CTcflag",#{type tcflag_t})
77 INTEGRAL_TYPE(CRLim,tyConCRlim,"CRLim",#{type rlim_t})
78
79 -- ToDo: blksize_t, clockid_t, blkcnt_t, fsblkcnt_t, fsfilcnt_t, id_t, key_t
80 -- suseconds_t, timer_t, useconds_t
81
82 -- Make an Fd type rather than using CInt everywhere
83 INTEGRAL_TYPE(Fd,tyConFd,"Fd",CInt)
84
85 -- nicer names, and backwards compatibility with POSIX library:
86 type LinkCount      = CNlink
87 type UserID         = CUid
88 type GroupID        = CGid