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