[project @ 2004-08-13 13:29:00 by simonmar]
[ghc.git] / libraries / base / System / Posix / Types.hs
1 {-# OPTIONS -fno-implicit-prelude #-}
2 -----------------------------------------------------------------------------
3 -- |
4 -- Module : System.Posix.Types
5 -- Copyright : (c) The University of Glasgow 2002
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 #include "ghcconfig.h"
18
19 module System.Posix.Types (
20
21 -- * POSIX data types
22 #if defined(HTYPE_DEV_T)
23 CDev,
24 #endif
25 #if defined(HTYPE_INO_T)
26 CIno,
27 #endif
28 #if defined(HTYPE_MODE_T)
29 CMode,
30 #endif
31 #if defined(HTYPE_OFF_T)
32 COff,
33 #endif
34 #if defined(HTYPE_PID_T)
35 CPid,
36 #endif
37 #if defined(HTYPE_SIZE_T) || defined(HTYPE_SSIZE_T)
38 CSsize,
39 #endif
40
41 #if defined(HTYPE_GID_T)
42 CGid,
43 #endif
44 #if defined(HTYPE_NLINK_T)
45 CNlink,
46 #endif
47 #if defined(HTYPE_UID_T)
48 CUid,
49 #endif
50 #if defined(HTYPE_CC_T)
51 CCc,
52 #endif
53 #if defined(HTYPE_SPEED_T)
54 CSpeed,
55 #endif
56 #if defined(HTYPE_TCFLAG_T)
57 CTcflag,
58 #endif
59 #if defined(HTYPE_RLIM_T)
60 CRLim,
61 #endif
62
63 Fd(..),
64
65 #if defined(HTYPE_NLINK_T)
66 LinkCount,
67 #endif
68 #if defined(HTYPE_UID_T)
69 UserID,
70 #endif
71 #if defined(HTYPE_GID_T)
72 GroupID,
73 #endif
74
75 ByteCount,
76 ClockTick,
77 EpochTime,
78 FileOffset,
79 ProcessID,
80 ProcessGroupID,
81 DeviceID,
82 FileID,
83 FileMode,
84 Limit
85 ) where
86
87 import Foreign
88 import Foreign.C
89 import Data.Typeable
90 import Data.Bits
91
92 #ifdef __GLASGOW_HASKELL__
93 import GHC.Base
94 import GHC.Enum
95 import GHC.Num
96 import GHC.Real
97 import GHC.Prim
98 import GHC.Read
99 import GHC.Show
100 #else
101 import Control.Monad
102 #endif
103
104 #include "Typeable.h"
105 #include "CTypes.h"
106
107 #if defined(HTYPE_DEV_T)
108 ARITHMETIC_TYPE(CDev,tyConCDev,"CDev",HTYPE_DEV_T)
109 #endif
110 #if defined(HTYPE_INO_T)
111 INTEGRAL_TYPE(CIno,tyConCIno,"CIno",HTYPE_INO_T)
112 #endif
113 #if defined(HTYPE_MODE_T)
114 INTEGRAL_TYPE(CMode,tyConCMode,"CMode",HTYPE_MODE_T)
115 #endif
116 #if defined(HTYPE_OFF_T)
117 INTEGRAL_TYPE(COff,tyConCOff,"COff",HTYPE_OFF_T)
118 #endif
119 #if defined(HTYPE_PID_T)
120 INTEGRAL_TYPE(CPid,tyConCPid,"CPid",HTYPE_PID_T)
121 #endif
122
123 #if defined(HTYPE_SIZE_T)
124 INTEGRAL_TYPE(CSsize,tyConCSsize,"CSsize",HTYPE_SIZE_T)
125 #endif
126
127 #if defined(HTYPE_SSIZE_T) && !defined(HTYPE_SIZE_T)
128 INTEGRAL_TYPE(CSsize,tyConCSsize,"CSsize",HTYPE_SSIZE_T)
129 #endif
130
131 #if defined(HTYPE_GID_T)
132 INTEGRAL_TYPE(CGid,tyConCGid,"CGid",HTYPE_GID_T)
133 #endif
134 #if defined(HTYPE_NLINK_T)
135 INTEGRAL_TYPE(CNlink,tyConCNlink,"CNlink",HTYPE_NLINK_T)
136 #endif
137
138 #if defined(HTYPE_UID_T)
139 INTEGRAL_TYPE(CUid,tyConCUid,"CUid",HTYPE_UID_T)
140 #endif
141 #if defined(HTYPE_CC_T)
142 ARITHMETIC_TYPE(CCc,tyConCCc,"CCc",HTYPE_CC_T)
143 #endif
144 #if defined(HTYPE_SPEED_T)
145 ARITHMETIC_TYPE(CSpeed,tyConCSpeed,"CSpeed",HTYPE_SPEED_T)
146 #endif
147 #if defined(HTYPE_TCFLAG_T)
148 INTEGRAL_TYPE(CTcflag,tyConCTcflag,"CTcflag",HTYPE_TCFLAG_T)
149 #endif
150 #if defined(HTYPE_RLIM_T)
151 INTEGRAL_TYPE(CRLim,tyConCRlim,"CRLim",HTYPE_RLIM_T)
152 #endif
153
154 -- ToDo: blksize_t, clockid_t, blkcnt_t, fsblkcnt_t, fsfilcnt_t, id_t, key_t
155 -- suseconds_t, timer_t, useconds_t
156
157 -- Make an Fd type rather than using CInt everywhere
158 INTEGRAL_TYPE(Fd,tyConFd,"Fd",CInt)
159
160 -- nicer names, and backwards compatibility with POSIX library:
161 #if defined(HTYPE_NLINK_T)
162 type LinkCount = CNlink
163 #endif
164 #if defined(HTYPE_UID_T)
165 type UserID = CUid
166 #endif
167 #if defined(HTYPE_GID_T)
168 type GroupID = CGid
169 #endif
170
171 type ByteCount = CSize
172 type ClockTick = CClock
173 type EpochTime = CTime
174 type DeviceID = CDev
175 type FileID = CIno
176 type FileMode = CMode
177 type ProcessID = CPid
178 type FileOffset = COff
179 type ProcessGroupID = CPid
180 type Limit = CLong
181