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