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