9bb85e298a86a1752626ecea8c4d8b6daa45ac10
[packages/base.git] / System / Posix / Types.hs
1 {-# LANGUAGE CPP
2 , NoImplicitPrelude
3 , MagicHash
4 , GeneralizedNewtypeDeriving
5 #-}
6 #ifdef __GLASGOW_HASKELL__
7 {-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}
8 #endif
9
10 -----------------------------------------------------------------------------
11 -- |
12 -- Module : System.Posix.Types
13 -- Copyright : (c) The University of Glasgow 2002
14 -- License : BSD-style (see the file libraries/base/LICENSE)
15 --
16 -- Maintainer : libraries@haskell.org
17 -- Stability : provisional
18 -- Portability : non-portable (requires POSIX)
19 --
20 -- POSIX data types: Haskell equivalents of the types defined by the
21 -- @\<sys\/types.h>@ C header on a POSIX system.
22 --
23 -----------------------------------------------------------------------------
24 #ifdef __NHC__
25 #define HTYPE_DEV_T
26 #define HTYPE_INO_T
27 #define HTYPE_MODE_T
28 #define HTYPE_OFF_T
29 #define HTYPE_PID_T
30 #define HTYPE_SSIZE_T
31 #define HTYPE_GID_T
32 #define HTYPE_NLINK_T
33 #define HTYPE_UID_T
34 #define HTYPE_CC_T
35 #define HTYPE_SPEED_T
36 #define HTYPE_TCFLAG_T
37 #define HTYPE_RLIM_T
38 #define HTYPE_NLINK_T
39 #define HTYPE_UID_T
40 #define HTYPE_GID_T
41 #else
42 #include "HsBaseConfig.h"
43 #endif
44
45 module System.Posix.Types (
46
47 -- * POSIX data types
48 #if defined(HTYPE_DEV_T)
49 CDev,
50 #endif
51 #if defined(HTYPE_INO_T)
52 CIno,
53 #endif
54 #if defined(HTYPE_MODE_T)
55 CMode,
56 #endif
57 #if defined(HTYPE_OFF_T)
58 COff,
59 #endif
60 #if defined(HTYPE_PID_T)
61 CPid,
62 #endif
63 #if defined(HTYPE_SSIZE_T)
64 CSsize,
65 #endif
66
67 #if defined(HTYPE_GID_T)
68 CGid,
69 #endif
70 #if defined(HTYPE_NLINK_T)
71 CNlink,
72 #endif
73 #if defined(HTYPE_UID_T)
74 CUid,
75 #endif
76 #if defined(HTYPE_CC_T)
77 CCc,
78 #endif
79 #if defined(HTYPE_SPEED_T)
80 CSpeed,
81 #endif
82 #if defined(HTYPE_TCFLAG_T)
83 CTcflag,
84 #endif
85 #if defined(HTYPE_RLIM_T)
86 CRLim,
87 #endif
88
89 Fd(..),
90
91 #if defined(HTYPE_NLINK_T)
92 LinkCount,
93 #endif
94 #if defined(HTYPE_UID_T)
95 UserID,
96 #endif
97 #if defined(HTYPE_GID_T)
98 GroupID,
99 #endif
100
101 ByteCount,
102 ClockTick,
103 EpochTime,
104 FileOffset,
105 ProcessID,
106 ProcessGroupID,
107 DeviceID,
108 FileID,
109 FileMode,
110 Limit
111 ) where
112
113 #ifdef __NHC__
114 import NHC.PosixTypes
115 import Foreign.C
116 #else
117
118 import Foreign
119 import Foreign.C
120 import Data.Typeable
121 -- import Data.Bits
122
123 #ifdef __GLASGOW_HASKELL__
124 import GHC.Base
125 import GHC.Enum
126 import GHC.Num
127 import GHC.Real
128 -- import GHC.Prim
129 import GHC.Read
130 import GHC.Show
131 #else
132 import Control.Monad
133 #endif
134
135 #include "CTypes.h"
136
137 #if defined(HTYPE_DEV_T)
138 ARITHMETIC_TYPE(CDev,tyConCDev,"CDev",HTYPE_DEV_T)
139 #endif
140 #if defined(HTYPE_INO_T)
141 INTEGRAL_TYPE(CIno,tyConCIno,"CIno",HTYPE_INO_T)
142 #endif
143 #if defined(HTYPE_MODE_T)
144 INTEGRAL_TYPE(CMode,tyConCMode,"CMode",HTYPE_MODE_T)
145 #endif
146 #if defined(HTYPE_OFF_T)
147 INTEGRAL_TYPE(COff,tyConCOff,"COff",HTYPE_OFF_T)
148 #endif
149 #if defined(HTYPE_PID_T)
150 INTEGRAL_TYPE(CPid,tyConCPid,"CPid",HTYPE_PID_T)
151 #endif
152
153 #if defined(HTYPE_SSIZE_T)
154 INTEGRAL_TYPE(CSsize,tyConCSsize,"CSsize",HTYPE_SSIZE_T)
155 #endif
156
157 #if defined(HTYPE_GID_T)
158 INTEGRAL_TYPE(CGid,tyConCGid,"CGid",HTYPE_GID_T)
159 #endif
160 #if defined(HTYPE_NLINK_T)
161 INTEGRAL_TYPE(CNlink,tyConCNlink,"CNlink",HTYPE_NLINK_T)
162 #endif
163
164 #if defined(HTYPE_UID_T)
165 INTEGRAL_TYPE(CUid,tyConCUid,"CUid",HTYPE_UID_T)
166 #endif
167 #if defined(HTYPE_CC_T)
168 ARITHMETIC_TYPE(CCc,tyConCCc,"CCc",HTYPE_CC_T)
169 #endif
170 #if defined(HTYPE_SPEED_T)
171 ARITHMETIC_TYPE(CSpeed,tyConCSpeed,"CSpeed",HTYPE_SPEED_T)
172 #endif
173 #if defined(HTYPE_TCFLAG_T)
174 INTEGRAL_TYPE(CTcflag,tyConCTcflag,"CTcflag",HTYPE_TCFLAG_T)
175 #endif
176 #if defined(HTYPE_RLIM_T)
177 INTEGRAL_TYPE(CRLim,tyConCRlim,"CRLim",HTYPE_RLIM_T)
178 #endif
179
180 -- ToDo: blksize_t, clockid_t, blkcnt_t, fsblkcnt_t, fsfilcnt_t, id_t, key_t
181 -- suseconds_t, timer_t, useconds_t
182
183 -- Make an Fd type rather than using CInt everywhere
184 INTEGRAL_TYPE(Fd,tyConFd,"Fd",CInt)
185
186 -- nicer names, and backwards compatibility with POSIX library:
187 #if defined(HTYPE_NLINK_T)
188 type LinkCount = CNlink
189 #endif
190 #if defined(HTYPE_UID_T)
191 type UserID = CUid
192 #endif
193 #if defined(HTYPE_GID_T)
194 type GroupID = CGid
195 #endif
196
197 #endif /* !__NHC__ */
198
199 type ByteCount = CSize
200 type ClockTick = CClock
201 type EpochTime = CTime
202 type DeviceID = CDev
203 type FileID = CIno
204 type FileMode = CMode
205 type ProcessID = CPid
206 type FileOffset = COff
207 type ProcessGroupID = CPid
208 type Limit = CLong
209