For nhc98 only, use hsc2hs to determine System.Posix.Types.
[haskell-directory.git] / NHC / PosixTypes.hsc
1 {-# OPTIONS_NHC98 -I/usr/include #-}
2 -----------------------------------------------------------------------------
3 -- |
4 -- Module      :  NHC.PosixTypes
5 -- Copyright   :  (c) Malcolm Wallace 2007
6 -- License     :  BSD-style (see the file libraries/base/LICENSE)
7 -- 
8 -- Maintainer  :  libraries@haskell.org
9 -- Stability   :  provisional
10 -- Portability :  non-portable (requires POSIX)
11 --
12 -- POSIX data types: Haskell equivalents of the types defined by the
13 -- @\<sys\/types.h>@ C header on a POSIX system.
14 --
15 -----------------------------------------------------------------------------
16
17 module NHC.PosixTypes (
18
19   -- * POSIX data types
20   CDev,
21   CIno,
22   CMode,
23   COff,
24   CPid,
25   CSsize,
26
27   CGid,
28   CNlink,
29   CUid,
30   CCc,
31   CSpeed,
32   CTcflag,
33   CRLim,
34
35   Fd(..),
36
37   LinkCount,
38   UserID,
39   GroupID,
40  ) where
41
42 import Foreign
43 import Foreign.C
44 import Data.Typeable
45 import Data.Bits
46 import Unsafe.Coerce
47
48 import Control.Monad
49
50
51 -- Curious hack to ensure that the CTypes macros are expanded *after* hsc2hs.
52 ##include "CTypes.h"
53 -- C header files that contain all the types we are looking for here.
54 #include <stdlib.h>
55 #include <unistd.h>
56 #include <sys/resource.h>
57 #include <termios.h>
58
59 ARITHMETIC_TYPE(CDev,tyConCDev,"CDev",#{type dev_t})
60 INTEGRAL_TYPE(CIno,tyConCIno,"CIno",#{type ino_t})
61 INTEGRAL_TYPE(CMode,tyConCMode,"CMode",#{type mode_t})
62 INTEGRAL_TYPE(COff,tyConCOff,"COff",#{type off_t})
63 INTEGRAL_TYPE(CPid,tyConCPid,"CPid",#{type pid_t})
64
65 INTEGRAL_TYPE(CSsize,tyConCSsize,"CSsize",#{type ssize_t})
66
67 INTEGRAL_TYPE(CGid,tyConCGid,"CGid",#{type gid_t})
68 INTEGRAL_TYPE(CNlink,tyConCNlink,"CNlink",#{type nlink_t})
69
70 INTEGRAL_TYPE(CUid,tyConCUid,"CUid",#{type uid_t})
71 ARITHMETIC_TYPE(CCc,tyConCCc,"CCc",#{type cc_t})
72 ARITHMETIC_TYPE(CSpeed,tyConCSpeed,"CSpeed",#{type speed_t})
73 INTEGRAL_TYPE(CTcflag,tyConCTcflag,"CTcflag",#{type tcflag_t})
74 INTEGRAL_TYPE(CRLim,tyConCRlim,"CRLim",#{type rlim_t})
75
76 -- ToDo: blksize_t, clockid_t, blkcnt_t, fsblkcnt_t, fsfilcnt_t, id_t, key_t
77 -- suseconds_t, timer_t, useconds_t
78
79 -- Make an Fd type rather than using CInt everywhere
80 INTEGRAL_TYPE(Fd,tyConFd,"Fd",CInt)
81
82 -- nicer names, and backwards compatibility with POSIX library:
83 type LinkCount      = CNlink
84 type UserID         = CUid
85 type GroupID        = CGid