Types.hs 5.14 KB
Newer Older
1
2
3
4
5
{-# LANGUAGE CPP #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE NoImplicitPrelude #-}
6
{-# LANGUAGE StandaloneDeriving #-}
7
{-# LANGUAGE Trustworthy #-}
8

9
10
11
12
13
-----------------------------------------------------------------------------
-- |
-- Module      :  System.Posix.Types
-- Copyright   :  (c) The University of Glasgow 2002
-- License     :  BSD-style (see the file libraries/base/LICENSE)
14
--
15
16
17
18
-- Maintainer  :  libraries@haskell.org
-- Stability   :  provisional
-- Portability :  non-portable (requires POSIX)
--
19
-- POSIX data types: Haskell equivalents of the types defined by the
20
-- @\<sys\/types.h>@ C header on a POSIX system.
21
22
--
-----------------------------------------------------------------------------
23
#include "HsBaseConfig.h"
24

25
module System.Posix.Types (
26
27

  -- * POSIX data types
28
29
30
31
32
33

  -- ** Platform differences
  -- | This module contains platform specific information about types.
  --   __/As such the types presented on this page reflect the platform
  --   on which the documentation was generated and may not coincide with
  --   the types on your platform./__
sof's avatar
sof committed
34
#if defined(HTYPE_DEV_T)
35
  CDev(..),
sof's avatar
sof committed
36
37
#endif
#if defined(HTYPE_INO_T)
38
  CIno(..),
sof's avatar
sof committed
39
40
#endif
#if defined(HTYPE_MODE_T)
41
  CMode(..),
sof's avatar
sof committed
42
43
#endif
#if defined(HTYPE_OFF_T)
44
  COff(..),
sof's avatar
sof committed
45
46
#endif
#if defined(HTYPE_PID_T)
47
  CPid(..),
sof's avatar
sof committed
48
#endif
sof's avatar
sof committed
49
#if defined(HTYPE_SSIZE_T)
50
  CSsize(..),
sof's avatar
sof committed
51
#endif
52

sof's avatar
sof committed
53
#if defined(HTYPE_GID_T)
54
  CGid(..),
sof's avatar
sof committed
55
56
#endif
#if defined(HTYPE_NLINK_T)
57
  CNlink(..),
sof's avatar
sof committed
58
59
#endif
#if defined(HTYPE_UID_T)
60
  CUid(..),
sof's avatar
sof committed
61
62
#endif
#if defined(HTYPE_CC_T)
63
  CCc(..),
sof's avatar
sof committed
64
65
#endif
#if defined(HTYPE_SPEED_T)
66
  CSpeed(..),
sof's avatar
sof committed
67
68
#endif
#if defined(HTYPE_TCFLAG_T)
69
  CTcflag(..),
sof's avatar
sof committed
70
71
#endif
#if defined(HTYPE_RLIM_T)
72
  CRLim(..),
73
#endif
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#if defined(HTYPE_BLKSIZE_T)
  CBlkSize(..),
#endif
#if defined(HTYPE_BLKCNT_T)
  CBlkCnt(..),
#endif
#if defined(HTYPE_CLOCKID_T)
  CClockId(..),
#endif
#if defined(HTYPE_FSBLKCNT_T)
  CFsBlkCnt(..),
#endif
#if defined(HTYPE_FSFILCNT_T)
  CFsFilCnt(..),
#endif
#if defined(HTYPE_ID_T)
  CId(..),
#endif
#if defined(HTYPE_KEY_T)
  CKey(..),
#endif
Ryan Scott's avatar
Ryan Scott committed
95
96
97
98
99
100
101
-- We can't support CTimer (timer_t) yet, as FPTOOLS_CHECK_HTYPE doesn't have
-- the ability to discern pointer types (like void*, which timer_t usually is)
-- from non-pointer types. See GHC Trac #12998.
--
-- #if defined(HTYPE_TIMER_T)
--   CTimer(..),
-- #endif
102
103
104

  Fd(..),

105
106
107
108
  -- See Note [Exporting constructors of marshallable foreign types]
  -- in Foreign.Ptr for why the constructors for these newtypes are
  -- exported.

sof's avatar
sof committed
109
#if defined(HTYPE_NLINK_T)
110
  LinkCount,
sof's avatar
sof committed
111
112
#endif
#if defined(HTYPE_UID_T)
113
  UserID,
sof's avatar
sof committed
114
115
#endif
#if defined(HTYPE_GID_T)
116
117
118
  GroupID,
#endif

119
120
121
122
123
124
125
126
  ByteCount,
  ClockTick,
  EpochTime,
  FileOffset,
  ProcessID,
  ProcessGroupID,
  DeviceID,
  FileID,
127
128
  FileMode,
  Limit
129
130
131
132
 ) where

import Foreign
import Foreign.C
133
-- import Data.Bits
134
135
136
137
138

import GHC.Base
import GHC.Enum
import GHC.Num
import GHC.Real
139
-- import GHC.Prim
140
141
142
143
144
import GHC.Read
import GHC.Show

#include "CTypes.h"

sof's avatar
sof committed
145
#if defined(HTYPE_DEV_T)
146
INTEGRAL_TYPE(CDev,HTYPE_DEV_T)
sof's avatar
sof committed
147
148
#endif
#if defined(HTYPE_INO_T)
149
INTEGRAL_TYPE(CIno,HTYPE_INO_T)
sof's avatar
sof committed
150
151
#endif
#if defined(HTYPE_MODE_T)
152
INTEGRAL_TYPE_WITH_CTYPE(CMode,mode_t,HTYPE_MODE_T)
sof's avatar
sof committed
153
154
#endif
#if defined(HTYPE_OFF_T)
155
INTEGRAL_TYPE(COff,HTYPE_OFF_T)
sof's avatar
sof committed
156
157
#endif
#if defined(HTYPE_PID_T)
158
INTEGRAL_TYPE(CPid,HTYPE_PID_T)
sof's avatar
sof committed
159
#endif
160

sof's avatar
sof committed
161
#if defined(HTYPE_SSIZE_T)
162
INTEGRAL_TYPE(CSsize,HTYPE_SSIZE_T)
163
164
#endif

sof's avatar
sof committed
165
#if defined(HTYPE_GID_T)
166
INTEGRAL_TYPE(CGid,HTYPE_GID_T)
sof's avatar
sof committed
167
168
#endif
#if defined(HTYPE_NLINK_T)
169
INTEGRAL_TYPE(CNlink,HTYPE_NLINK_T)
sof's avatar
sof committed
170
171
172
#endif

#if defined(HTYPE_UID_T)
173
INTEGRAL_TYPE(CUid,HTYPE_UID_T)
sof's avatar
sof committed
174
175
#endif
#if defined(HTYPE_CC_T)
176
ARITHMETIC_TYPE(CCc,HTYPE_CC_T)
sof's avatar
sof committed
177
178
#endif
#if defined(HTYPE_SPEED_T)
179
ARITHMETIC_TYPE(CSpeed,HTYPE_SPEED_T)
sof's avatar
sof committed
180
181
#endif
#if defined(HTYPE_TCFLAG_T)
182
INTEGRAL_TYPE(CTcflag,HTYPE_TCFLAG_T)
sof's avatar
sof committed
183
184
#endif
#if defined(HTYPE_RLIM_T)
185
INTEGRAL_TYPE(CRLim,HTYPE_RLIM_T)
186
187
#endif

188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#if defined(HTYPE_BLKSIZE_T)
-- | @since 4.10.0.0
INTEGRAL_TYPE_WITH_CTYPE(CBlkSize,blksize_t,HTYPE_BLKSIZE_T)
#endif
#if defined(HTYPE_BLKCNT_T)
-- | @since 4.10.0.0
INTEGRAL_TYPE_WITH_CTYPE(CBlkCnt,blkcnt_t,HTYPE_BLKCNT_T)
#endif
#if defined(HTYPE_CLOCKID_T)
-- | @since 4.10.0.0
INTEGRAL_TYPE_WITH_CTYPE(CClockId,clockid_t,HTYPE_CLOCKID_T)
#endif
#if defined(HTYPE_FSBLKCNT_T)
-- | @since 4.10.0.0
INTEGRAL_TYPE_WITH_CTYPE(CFsBlkCnt,fsblkcnt_t,HTYPE_FSBLKCNT_T)
#endif
#if defined(HTYPE_FSFILCNT_T)
-- | @since 4.10.0.0
INTEGRAL_TYPE_WITH_CTYPE(CFsFilCnt,fsfilcnt_t,HTYPE_FSFILCNT_T)
#endif
#if defined(HTYPE_ID_T)
-- | @since 4.10.0.0
INTEGRAL_TYPE_WITH_CTYPE(CId,id_t,HTYPE_ID_T)
#endif
#if defined(HTYPE_KEY_T)
-- | @since 4.10.0.0
INTEGRAL_TYPE_WITH_CTYPE(CKey,key_t,HTYPE_KEY_T)
#endif
216

217
-- Make an Fd type rather than using CInt everywhere
218
INTEGRAL_TYPE(Fd,CInt)
219
220

-- nicer names, and backwards compatibility with POSIX library:
sof's avatar
sof committed
221
#if defined(HTYPE_NLINK_T)
222
type LinkCount      = CNlink
sof's avatar
sof committed
223
224
#endif
#if defined(HTYPE_UID_T)
225
type UserID         = CUid
sof's avatar
sof committed
226
227
#endif
#if defined(HTYPE_GID_T)
228
229
230
type GroupID        = CGid
#endif

231
232
233
234
235
236
237
238
239
type ByteCount      = CSize
type ClockTick      = CClock
type EpochTime      = CTime
type DeviceID       = CDev
type FileID         = CIno
type FileMode       = CMode
type ProcessID      = CPid
type FileOffset     = COff
type ProcessGroupID = CPid
Don Stewart's avatar
Don Stewart committed
240
type Limit          = CLong