MacOS 10.3 needs #include <libc.h> as well
[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 <libc.h>
55 #include <stdlib.h>
56 #include <unistd.h>
57 #include <sys/resource.h>
58 #include <termios.h>
59
60 ARITHMETIC_TYPE(CDev,tyConCDev,"CDev",#{type dev_t})
61 INTEGRAL_TYPE(CIno,tyConCIno,"CIno",#{type ino_t})
62 INTEGRAL_TYPE(CMode,tyConCMode,"CMode",#{type mode_t})
63 INTEGRAL_TYPE(COff,tyConCOff,"COff",#{type off_t})
64 INTEGRAL_TYPE(CPid,tyConCPid,"CPid",#{type pid_t})
65
66 INTEGRAL_TYPE(CSsize,tyConCSsize,"CSsize",#{type ssize_t})
67
68 INTEGRAL_TYPE(CGid,tyConCGid,"CGid",#{type gid_t})
69 INTEGRAL_TYPE(CNlink,tyConCNlink,"CNlink",#{type nlink_t})
70
71 INTEGRAL_TYPE(CUid,tyConCUid,"CUid",#{type uid_t})
72 ARITHMETIC_TYPE(CCc,tyConCCc,"CCc",#{type cc_t})
73 ARITHMETIC_TYPE(CSpeed,tyConCSpeed,"CSpeed",#{type speed_t})
74 INTEGRAL_TYPE(CTcflag,tyConCTcflag,"CTcflag",#{type tcflag_t})
75 INTEGRAL_TYPE(CRLim,tyConCRlim,"CRLim",#{type rlim_t})
76
77 -- ToDo: blksize_t, clockid_t, blkcnt_t, fsblkcnt_t, fsfilcnt_t, id_t, key_t
78 -- suseconds_t, timer_t, useconds_t
79
80 -- Make an Fd type rather than using CInt everywhere
81 INTEGRAL_TYPE(Fd,tyConFd,"Fd",CInt)
82
83 -- nicer names, and backwards compatibility with POSIX library:
84 type LinkCount      = CNlink
85 type UserID         = CUid
86 type GroupID        = CGid