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