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