Fix layout to comply with H'98.
[ghc-base.git] / System / Posix / Internals.hs
1 {-# OPTIONS_GHC -XNoImplicitPrelude #-}
2 {-# OPTIONS_GHC -fno-warn-unused-binds #-}
3 {-# OPTIONS_HADDOCK hide #-}
4
5 -----------------------------------------------------------------------------
6 -- |
7 -- Module      :  System.Posix.Internals
8 -- Copyright   :  (c) The University of Glasgow, 1992-2002
9 -- License     :  see libraries/base/LICENSE
10 -- 
11 -- Maintainer  :  cvs-ghc@haskell.org
12 -- Stability   :  internal
13 -- Portability :  non-portable (requires POSIX)
14 --
15 -- POSIX support layer for the standard libraries.
16 -- This library is built on *every* platform, including Win32.
17 --
18 -- Non-posix compliant in order to support the following features:
19 --      * S_ISSOCK (no sockets in POSIX)
20 --
21 -----------------------------------------------------------------------------
22
23 -- #hide
24 module System.Posix.Internals where
25
26 #ifdef __NHC__
27 #define HTYPE_TCFLAG_T
28 #else
29 # include "HsBaseConfig.h"
30 #endif
31
32 #if ! (defined(mingw32_HOST_OS) || defined(__MINGW32__))
33 import Control.Monad
34 #endif
35 import System.Posix.Types
36
37 import Foreign
38 import Foreign.C
39
40 import Data.Bits
41 import Data.Maybe
42
43 #if !defined(HTYPE_TCFLAG_T)
44 import System.IO.Error
45 #endif
46
47 #if __GLASGOW_HASKELL__
48 import GHC.Base
49 import GHC.Num
50 import GHC.Real
51 import GHC.IOBase
52 #elif __HUGS__
53 import Hugs.Prelude (IOException(..), IOErrorType(..))
54 import Hugs.IO (IOMode(..))
55 #elif __NHC__
56 import System.IO
57 import Control.Exception
58 import DIOError
59 #endif
60
61 #ifdef __HUGS__
62 {-# CFILES cbits/PrelIOUtils.c cbits/dirUtils.c cbits/consUtils.c #-}
63 #endif
64
65 -- ---------------------------------------------------------------------------
66 -- Types
67
68 type CDir       = ()
69 type CDirent    = ()
70 type CFLock     = ()
71 type CGroup     = ()
72 type CLconv     = ()
73 type CPasswd    = ()
74 type CSigaction = ()
75 type CSigset    = ()
76 type CStat      = ()
77 type CTermios   = ()
78 type CTm        = ()
79 type CTms       = ()
80 type CUtimbuf   = ()
81 type CUtsname   = ()
82
83 #ifndef __GLASGOW_HASKELL__
84 type FD = CInt
85 #endif
86
87 -- ---------------------------------------------------------------------------
88 -- stat()-related stuff
89
90 fdFileSize :: FD -> IO Integer
91 fdFileSize fd = 
92   allocaBytes sizeof_stat $ \ p_stat -> do
93     throwErrnoIfMinus1Retry "fileSize" $
94         c_fstat fd p_stat
95     c_mode <- st_mode p_stat :: IO CMode 
96     if not (s_isreg c_mode)
97         then return (-1)
98         else do
99       c_size <- st_size p_stat
100       return (fromIntegral c_size)
101
102 data FDType  = Directory | Stream | RegularFile | RawDevice
103                deriving (Eq)
104
105 fileType :: FilePath -> IO FDType
106 fileType file =
107   allocaBytes sizeof_stat $ \ p_stat -> do
108   withCString file $ \p_file -> do
109     throwErrnoIfMinus1Retry "fileType" $
110       c_stat p_file p_stat
111     statGetType p_stat
112
113 -- NOTE: On Win32 platforms, this will only work with file descriptors
114 -- referring to file handles. i.e., it'll fail for socket FDs.
115 fdStat :: FD -> IO (FDType, CDev, CIno)
116 fdStat fd = 
117   allocaBytes sizeof_stat $ \ p_stat -> do
118     throwErrnoIfMinus1Retry "fdType" $
119         c_fstat fd p_stat
120     ty <- statGetType p_stat
121     dev <- st_dev p_stat
122     ino <- st_ino p_stat
123     return (ty,dev,ino)
124     
125 fdType :: FD -> IO FDType
126 fdType fd = do (ty,_,_) <- fdStat fd; return ty
127
128 statGetType :: Ptr CStat -> IO FDType
129 statGetType p_stat = do
130   c_mode <- st_mode p_stat :: IO CMode
131   case () of
132       _ | s_isdir c_mode        -> return Directory
133         | s_isfifo c_mode || s_issock c_mode || s_ischr  c_mode
134                                 -> return Stream
135         | s_isreg c_mode        -> return RegularFile
136          -- Q: map char devices to RawDevice too?
137         | s_isblk c_mode        -> return RawDevice
138         | otherwise             -> ioError ioe_unknownfiletype
139     
140 ioe_unknownfiletype :: IOException
141 #ifndef __NHC__
142 ioe_unknownfiletype = IOError Nothing UnsupportedOperation "fdType"
143                         "unknown file type"
144 #  if __GLASGOW_HASKELL__
145                         Nothing
146 #  endif
147                         Nothing
148 #else
149 ioe_unknownfiletype = UserError "fdType" "unknown file type"
150 #endif
151
152 #if __GLASGOW_HASKELL__ && (defined(mingw32_HOST_OS) || defined(__MINGW32__))
153 closeFd :: Bool -> CInt -> IO CInt
154 closeFd isStream fd 
155   | isStream  = c_closesocket fd
156   | otherwise = c_close fd
157
158 foreign import stdcall unsafe "HsBase.h closesocket"
159    c_closesocket :: CInt -> IO CInt
160 #endif
161
162 fdGetMode :: FD -> IO IOMode
163 #if defined(mingw32_HOST_OS) || defined(__MINGW32__)
164 fdGetMode _ = do
165     -- We don't have a way of finding out which flags are set on FDs
166     -- on Windows, so make a handle that thinks that anything goes.
167     let flags = o_RDWR
168 #else
169 fdGetMode fd = do
170     flags <- throwErrnoIfMinus1Retry "fdGetMode" 
171                 (c_fcntl_read fd const_f_getfl)
172 #endif
173     let
174        wH  = (flags .&. o_WRONLY) /= 0
175        aH  = (flags .&. o_APPEND) /= 0
176        rwH = (flags .&. o_RDWR) /= 0
177
178        mode
179          | wH && aH  = AppendMode
180          | wH        = WriteMode
181          | rwH       = ReadWriteMode
182          | otherwise = ReadMode
183           
184     return mode
185
186 -- ---------------------------------------------------------------------------
187 -- Terminal-related stuff
188
189 fdIsTTY :: FD -> IO Bool
190 fdIsTTY fd = c_isatty fd >>= return.toBool
191
192 #if defined(HTYPE_TCFLAG_T)
193
194 setEcho :: FD -> Bool -> IO ()
195 setEcho fd on = do
196   tcSetAttr fd $ \ p_tios -> do
197     lflag <- c_lflag p_tios :: IO CTcflag
198     let new_lflag
199          | on        = lflag .|. fromIntegral const_echo
200          | otherwise = lflag .&. complement (fromIntegral const_echo)
201     poke_c_lflag p_tios (new_lflag :: CTcflag)
202
203 getEcho :: FD -> IO Bool
204 getEcho fd = do
205   tcSetAttr fd $ \ p_tios -> do
206     lflag <- c_lflag p_tios :: IO CTcflag
207     return ((lflag .&. fromIntegral const_echo) /= 0)
208
209 setCooked :: FD -> Bool -> IO ()
210 setCooked fd cooked = 
211   tcSetAttr fd $ \ p_tios -> do
212
213     -- turn on/off ICANON
214     lflag <- c_lflag p_tios :: IO CTcflag
215     let new_lflag | cooked    = lflag .|. (fromIntegral const_icanon)
216                   | otherwise = lflag .&. complement (fromIntegral const_icanon)
217     poke_c_lflag p_tios (new_lflag :: CTcflag)
218
219     -- set VMIN & VTIME to 1/0 respectively
220     when (not cooked) $ do
221             c_cc <- ptr_c_cc p_tios
222             let vmin  = (c_cc `plusPtr` (fromIntegral const_vmin))  :: Ptr Word8
223                 vtime = (c_cc `plusPtr` (fromIntegral const_vtime)) :: Ptr Word8
224             poke vmin  1
225             poke vtime 0
226
227 tcSetAttr :: FD -> (Ptr CTermios -> IO a) -> IO a
228 tcSetAttr fd fun = do
229      allocaBytes sizeof_termios  $ \p_tios -> do
230         throwErrnoIfMinus1Retry "tcSetAttr"
231            (c_tcgetattr fd p_tios)
232
233 #ifdef __GLASGOW_HASKELL__
234         -- Save a copy of termios, if this is a standard file descriptor.
235         -- These terminal settings are restored in hs_exit().
236         when (fd <= 2) $ do
237           p <- get_saved_termios fd
238           when (p == nullPtr) $ do
239              saved_tios <- mallocBytes sizeof_termios
240              copyBytes saved_tios p_tios sizeof_termios
241              set_saved_termios fd saved_tios
242 #endif
243
244         -- tcsetattr() when invoked by a background process causes the process
245         -- to be sent SIGTTOU regardless of whether the process has TOSTOP set
246         -- in its terminal flags (try it...).  This function provides a
247         -- wrapper which temporarily blocks SIGTTOU around the call, making it
248         -- transparent.
249         allocaBytes sizeof_sigset_t $ \ p_sigset -> do
250           allocaBytes sizeof_sigset_t $ \ p_old_sigset -> do
251              c_sigemptyset p_sigset
252              c_sigaddset   p_sigset const_sigttou
253              c_sigprocmask const_sig_block p_sigset p_old_sigset
254              r <- fun p_tios  -- do the business
255              throwErrnoIfMinus1Retry_ "tcSetAttr" $
256                  c_tcsetattr fd const_tcsanow p_tios
257              c_sigprocmask const_sig_setmask p_old_sigset nullPtr
258              return r
259
260 #ifdef __GLASGOW_HASKELL__
261 foreign import ccall unsafe "HsBase.h __hscore_get_saved_termios"
262    get_saved_termios :: CInt -> IO (Ptr CTermios)
263
264 foreign import ccall unsafe "HsBase.h __hscore_set_saved_termios"
265    set_saved_termios :: CInt -> (Ptr CTermios) -> IO ()
266 #endif
267
268 #else
269
270 -- 'raw' mode for Win32 means turn off 'line input' (=> buffering and
271 -- character translation for the console.) The Win32 API for doing
272 -- this is GetConsoleMode(), which also requires echoing to be disabled
273 -- when turning off 'line input' processing. Notice that turning off
274 -- 'line input' implies enter/return is reported as '\r' (and it won't
275 -- report that character until another character is input..odd.) This
276 -- latter feature doesn't sit too well with IO actions like IO.hGetLine..
277 -- consider yourself warned.
278 setCooked :: FD -> Bool -> IO ()
279 setCooked fd cooked = do
280   x <- set_console_buffering fd (if cooked then 1 else 0)
281   if (x /= 0)
282    then ioError (ioe_unk_error "setCooked" "failed to set buffering")
283    else return ()
284
285 ioe_unk_error :: String -> String -> IOException
286 ioe_unk_error loc msg 
287 #ifndef __NHC__
288  = ioeSetErrorString (mkIOError OtherError loc Nothing Nothing) msg
289 #else
290  = UserError loc msg
291 #endif
292
293 -- Note: echoing goes hand in hand with enabling 'line input' / raw-ness
294 -- for Win32 consoles, hence setEcho ends up being the inverse of setCooked.
295 setEcho :: FD -> Bool -> IO ()
296 setEcho fd on = do
297   x <- set_console_echo fd (if on then 1 else 0)
298   if (x /= 0)
299    then ioError (ioe_unk_error "setEcho" "failed to set echoing")
300    else return ()
301
302 getEcho :: FD -> IO Bool
303 getEcho fd = do
304   r <- get_console_echo fd
305   if (r == (-1))
306    then ioError (ioe_unk_error "getEcho" "failed to get echoing")
307    else return (r == 1)
308
309 foreign import ccall unsafe "consUtils.h set_console_buffering__"
310    set_console_buffering :: CInt -> CInt -> IO CInt
311
312 foreign import ccall unsafe "consUtils.h set_console_echo__"
313    set_console_echo :: CInt -> CInt -> IO CInt
314
315 foreign import ccall unsafe "consUtils.h get_console_echo__"
316    get_console_echo :: CInt -> IO CInt
317
318 #endif
319
320 -- ---------------------------------------------------------------------------
321 -- Turning on non-blocking for a file descriptor
322
323 setNonBlockingFD :: FD -> IO ()
324 #if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
325 setNonBlockingFD fd = do
326   flags <- throwErrnoIfMinus1Retry "setNonBlockingFD"
327                  (c_fcntl_read fd const_f_getfl)
328   -- An error when setting O_NONBLOCK isn't fatal: on some systems 
329   -- there are certain file handles on which this will fail (eg. /dev/null
330   -- on FreeBSD) so we throw away the return code from fcntl_write.
331   unless (testBit flags (fromIntegral o_NONBLOCK)) $ do
332     c_fcntl_write fd const_f_setfl (fromIntegral (flags .|. o_NONBLOCK))
333     return ()
334 #else
335
336 -- bogus defns for win32
337 setNonBlockingFD _ = return ()
338
339 #endif
340
341 -- -----------------------------------------------------------------------------
342 -- Set close-on-exec for a file descriptor
343
344 #if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
345 setCloseOnExec :: FD -> IO ()
346 setCloseOnExec fd = do
347   throwErrnoIfMinus1 "setCloseOnExec" $
348     c_fcntl_write fd const_f_setfd const_fd_cloexec
349   return ()
350 #endif
351
352 -- -----------------------------------------------------------------------------
353 -- foreign imports
354
355 foreign import ccall unsafe "HsBase.h access"
356    c_access :: CString -> CInt -> IO CInt
357
358 foreign import ccall unsafe "HsBase.h chmod"
359    c_chmod :: CString -> CMode -> IO CInt
360
361 foreign import ccall unsafe "HsBase.h close"
362    c_close :: CInt -> IO CInt
363
364 foreign import ccall unsafe "HsBase.h closedir" 
365    c_closedir :: Ptr CDir -> IO CInt
366
367 foreign import ccall unsafe "HsBase.h creat"
368    c_creat :: CString -> CMode -> IO CInt
369
370 foreign import ccall unsafe "HsBase.h dup"
371    c_dup :: CInt -> IO CInt
372
373 foreign import ccall unsafe "HsBase.h dup2"
374    c_dup2 :: CInt -> CInt -> IO CInt
375
376 foreign import ccall unsafe "HsBase.h __hscore_fstat"
377    c_fstat :: CInt -> Ptr CStat -> IO CInt
378
379 foreign import ccall unsafe "HsBase.h isatty"
380    c_isatty :: CInt -> IO CInt
381
382 #if defined(mingw32_HOST_OS) || defined(__MINGW32__)
383 foreign import ccall unsafe "HsBase.h __hscore_lseek"
384    c_lseek :: CInt -> Int64 -> CInt -> IO Int64
385 #else
386 foreign import ccall unsafe "HsBase.h __hscore_lseek"
387    c_lseek :: CInt -> COff -> CInt -> IO COff
388 #endif
389
390 foreign import ccall unsafe "HsBase.h __hscore_lstat"
391    lstat :: CString -> Ptr CStat -> IO CInt
392
393 foreign import ccall unsafe "HsBase.h __hscore_open"
394    c_open :: CString -> CInt -> CMode -> IO CInt
395
396 foreign import ccall unsafe "HsBase.h opendir" 
397    c_opendir :: CString  -> IO (Ptr CDir)
398
399 foreign import ccall unsafe "HsBase.h __hscore_mkdir"
400    mkdir :: CString -> CInt -> IO CInt
401
402 foreign import ccall unsafe "HsBase.h read" 
403    c_read :: CInt -> Ptr CChar -> CSize -> IO CSsize
404
405 foreign import ccall unsafe "HsBase.h rewinddir"
406    c_rewinddir :: Ptr CDir -> IO ()
407
408 foreign import ccall unsafe "HsBase.h __hscore_stat"
409    c_stat :: CString -> Ptr CStat -> IO CInt
410
411 foreign import ccall unsafe "HsBase.h umask"
412    c_umask :: CMode -> IO CMode
413
414 foreign import ccall unsafe "HsBase.h write" 
415    c_write :: CInt -> Ptr CChar -> CSize -> IO CSsize
416
417 foreign import ccall unsafe "HsBase.h __hscore_ftruncate"
418    c_ftruncate :: CInt -> COff -> IO CInt
419
420 foreign import ccall unsafe "HsBase.h unlink"
421    c_unlink :: CString -> IO CInt
422
423 foreign import ccall unsafe "HsBase.h getpid"
424    c_getpid :: IO CPid
425
426 #if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
427 foreign import ccall unsafe "HsBase.h fcntl"
428    c_fcntl_read  :: CInt -> CInt -> IO CInt
429
430 foreign import ccall unsafe "HsBase.h fcntl"
431    c_fcntl_write :: CInt -> CInt -> CLong -> IO CInt
432
433 foreign import ccall unsafe "HsBase.h fcntl"
434    c_fcntl_lock  :: CInt -> CInt -> Ptr CFLock -> IO CInt
435
436 foreign import ccall unsafe "HsBase.h fork"
437    c_fork :: IO CPid 
438
439 foreign import ccall unsafe "HsBase.h link"
440    c_link :: CString -> CString -> IO CInt
441
442 foreign import ccall unsafe "HsBase.h mkfifo"
443    c_mkfifo :: CString -> CMode -> IO CInt
444
445 foreign import ccall unsafe "HsBase.h pipe"
446    c_pipe :: Ptr CInt -> IO CInt
447
448 foreign import ccall unsafe "HsBase.h __hscore_sigemptyset"
449    c_sigemptyset :: Ptr CSigset -> IO CInt
450
451 foreign import ccall unsafe "HsBase.h __hscore_sigaddset"
452    c_sigaddset :: Ptr CSigset -> CInt -> IO CInt
453
454 foreign import ccall unsafe "HsBase.h sigprocmask"
455    c_sigprocmask :: CInt -> Ptr CSigset -> Ptr CSigset -> IO CInt
456
457 foreign import ccall unsafe "HsBase.h tcgetattr"
458    c_tcgetattr :: CInt -> Ptr CTermios -> IO CInt
459
460 foreign import ccall unsafe "HsBase.h tcsetattr"
461    c_tcsetattr :: CInt -> CInt -> Ptr CTermios -> IO CInt
462
463 foreign import ccall unsafe "HsBase.h utime"
464    c_utime :: CString -> Ptr CUtimbuf -> IO CInt
465
466 foreign import ccall unsafe "HsBase.h waitpid"
467    c_waitpid :: CPid -> Ptr CInt -> CInt -> IO CPid
468 #endif
469
470 -- traversing directories
471 foreign import ccall unsafe "dirUtils.h __hscore_readdir"
472   readdir  :: Ptr CDir -> Ptr (Ptr CDirent) -> IO CInt
473  
474 foreign import ccall unsafe "HsBase.h __hscore_free_dirent"
475   freeDirEnt  :: Ptr CDirent -> IO ()
476  
477 foreign import ccall unsafe "HsBase.h __hscore_end_of_dir"
478   end_of_dir :: CInt
479  
480 foreign import ccall unsafe "HsBase.h __hscore_d_name"
481   d_name :: Ptr CDirent -> IO CString
482
483 -- POSIX flags only:
484 foreign import ccall unsafe "HsBase.h __hscore_o_rdonly" o_RDONLY :: CInt
485 foreign import ccall unsafe "HsBase.h __hscore_o_wronly" o_WRONLY :: CInt
486 foreign import ccall unsafe "HsBase.h __hscore_o_rdwr"   o_RDWR   :: CInt
487 foreign import ccall unsafe "HsBase.h __hscore_o_append" o_APPEND :: CInt
488 foreign import ccall unsafe "HsBase.h __hscore_o_creat"  o_CREAT  :: CInt
489 foreign import ccall unsafe "HsBase.h __hscore_o_excl"   o_EXCL   :: CInt
490 foreign import ccall unsafe "HsBase.h __hscore_o_trunc"  o_TRUNC  :: CInt
491
492 -- non-POSIX flags.
493 foreign import ccall unsafe "HsBase.h __hscore_o_noctty"   o_NOCTTY   :: CInt
494 foreign import ccall unsafe "HsBase.h __hscore_o_nonblock" o_NONBLOCK :: CInt
495 foreign import ccall unsafe "HsBase.h __hscore_o_binary"   o_BINARY   :: CInt
496
497 foreign import ccall unsafe "HsBase.h __hscore_s_isreg"  c_s_isreg  :: CMode -> CInt
498 foreign import ccall unsafe "HsBase.h __hscore_s_ischr"  c_s_ischr  :: CMode -> CInt
499 foreign import ccall unsafe "HsBase.h __hscore_s_isblk"  c_s_isblk  :: CMode -> CInt
500 foreign import ccall unsafe "HsBase.h __hscore_s_isdir"  c_s_isdir  :: CMode -> CInt
501 foreign import ccall unsafe "HsBase.h __hscore_s_isfifo" c_s_isfifo :: CMode -> CInt
502
503 s_isreg  :: CMode -> Bool
504 s_isreg cm = c_s_isreg cm /= 0
505 s_ischr  :: CMode -> Bool
506 s_ischr cm = c_s_ischr cm /= 0
507 s_isblk  :: CMode -> Bool
508 s_isblk cm = c_s_isblk cm /= 0
509 s_isdir  :: CMode -> Bool
510 s_isdir cm = c_s_isdir cm /= 0
511 s_isfifo :: CMode -> Bool
512 s_isfifo cm = c_s_isfifo cm /= 0
513
514 foreign import ccall unsafe "HsBase.h __hscore_sizeof_stat" sizeof_stat :: Int
515 foreign import ccall unsafe "HsBase.h __hscore_st_mtime" st_mtime :: Ptr CStat -> IO CTime
516 #ifdef mingw32_HOST_OS
517 foreign import ccall unsafe "HsBase.h __hscore_st_size" st_size :: Ptr CStat -> IO Int64
518 #else
519 foreign import ccall unsafe "HsBase.h __hscore_st_size" st_size :: Ptr CStat -> IO COff
520 #endif
521 foreign import ccall unsafe "HsBase.h __hscore_st_mode" st_mode :: Ptr CStat -> IO CMode
522 foreign import ccall unsafe "HsBase.h __hscore_st_dev" st_dev :: Ptr CStat -> IO CDev
523 foreign import ccall unsafe "HsBase.h __hscore_st_ino" st_ino :: Ptr CStat -> IO CIno
524
525 foreign import ccall unsafe "HsBase.h __hscore_echo"         const_echo :: CInt
526 foreign import ccall unsafe "HsBase.h __hscore_tcsanow"      const_tcsanow :: CInt
527 foreign import ccall unsafe "HsBase.h __hscore_icanon"       const_icanon :: CInt
528 foreign import ccall unsafe "HsBase.h __hscore_vmin"         const_vmin   :: CInt
529 foreign import ccall unsafe "HsBase.h __hscore_vtime"        const_vtime  :: CInt
530 foreign import ccall unsafe "HsBase.h __hscore_sigttou"      const_sigttou :: CInt
531 foreign import ccall unsafe "HsBase.h __hscore_sig_block"    const_sig_block :: CInt
532 foreign import ccall unsafe "HsBase.h __hscore_sig_setmask"  const_sig_setmask :: CInt
533 foreign import ccall unsafe "HsBase.h __hscore_f_getfl"      const_f_getfl :: CInt
534 foreign import ccall unsafe "HsBase.h __hscore_f_setfl"      const_f_setfl :: CInt
535 foreign import ccall unsafe "HsBase.h __hscore_f_setfd"      const_f_setfd :: CInt
536 foreign import ccall unsafe "HsBase.h __hscore_fd_cloexec"   const_fd_cloexec :: CLong
537
538 #if defined(HTYPE_TCFLAG_T)
539 foreign import ccall unsafe "HsBase.h __hscore_sizeof_termios"  sizeof_termios :: Int
540 foreign import ccall unsafe "HsBase.h __hscore_sizeof_sigset_t" sizeof_sigset_t :: Int
541
542 foreign import ccall unsafe "HsBase.h __hscore_lflag" c_lflag :: Ptr CTermios -> IO CTcflag
543 foreign import ccall unsafe "HsBase.h __hscore_poke_lflag" poke_c_lflag :: Ptr CTermios -> CTcflag -> IO ()
544 foreign import ccall unsafe "HsBase.h __hscore_ptr_c_cc" ptr_c_cc  :: Ptr CTermios -> IO (Ptr Word8)
545 #endif
546
547 s_issock :: CMode -> Bool
548 #if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
549 s_issock cmode = c_s_issock cmode /= 0
550 foreign import ccall unsafe "HsBase.h __hscore_s_issock" c_s_issock :: CMode -> CInt
551 #else
552 s_issock _ = False
553 #endif