-{-# OPTIONS_GHC -fno-implicit-prelude #-}
+{-# OPTIONS_GHC -XNoImplicitPrelude #-}
+{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_HADDOCK hide #-}
-----------------------------------------------------------------------------
#include "HsBaseConfig.h"
+#if ! (defined(mingw32_HOST_OS) || defined(__MINGW32__))
import Control.Monad
+#endif
import System.Posix.Types
import Foreign
fdType :: FD -> IO FDType
fdType fd = do (ty,_,_) <- fdStat fd; return ty
+statGetType :: Ptr CStat -> IO FDType
statGetType p_stat = do
c_mode <- st_mode p_stat :: IO CMode
case () of
| s_isblk c_mode -> return RawDevice
| otherwise -> ioError ioe_unknownfiletype
-
+ioe_unknownfiletype :: IOException
ioe_unknownfiletype = IOError Nothing UnsupportedOperation "fdType"
"unknown file type" Nothing
#endif
fdGetMode :: FD -> IO IOMode
-fdGetMode fd = do
#if defined(mingw32_HOST_OS) || defined(__MINGW32__)
+fdGetMode _ = do
-- We don't have a way of finding out which flags are set on FDs
-- on Windows, so make a handle that thinks that anything goes.
let flags = o_RDWR
#else
+fdGetMode fd = do
flags <- throwErrnoIfMinus1Retry "fdGetMode"
(c_fcntl_read fd const_f_getfl)
#endif
setEcho :: FD -> Bool -> IO ()
setEcho fd on = do
tcSetAttr fd $ \ p_tios -> do
- c_lflag <- c_lflag p_tios :: IO CTcflag
- let new_c_lflag
- | on = c_lflag .|. fromIntegral const_echo
- | otherwise = c_lflag .&. complement (fromIntegral const_echo)
- poke_c_lflag p_tios (new_c_lflag :: CTcflag)
+ lflag <- c_lflag p_tios :: IO CTcflag
+ let new_lflag
+ | on = lflag .|. fromIntegral const_echo
+ | otherwise = lflag .&. complement (fromIntegral const_echo)
+ poke_c_lflag p_tios (new_lflag :: CTcflag)
getEcho :: FD -> IO Bool
getEcho fd = do
tcSetAttr fd $ \ p_tios -> do
- c_lflag <- c_lflag p_tios :: IO CTcflag
- return ((c_lflag .&. fromIntegral const_echo) /= 0)
+ lflag <- c_lflag p_tios :: IO CTcflag
+ return ((lflag .&. fromIntegral const_echo) /= 0)
setCooked :: FD -> Bool -> IO ()
setCooked fd cooked =
tcSetAttr fd $ \ p_tios -> do
-- turn on/off ICANON
- c_lflag <- c_lflag p_tios :: IO CTcflag
- let new_c_lflag | cooked = c_lflag .|. (fromIntegral const_icanon)
- | otherwise = c_lflag .&. complement (fromIntegral const_icanon)
- poke_c_lflag p_tios (new_c_lflag :: CTcflag)
+ lflag <- c_lflag p_tios :: IO CTcflag
+ let new_lflag | cooked = lflag .|. (fromIntegral const_icanon)
+ | otherwise = lflag .&. complement (fromIntegral const_icanon)
+ poke_c_lflag p_tios (new_lflag :: CTcflag)
-- set VMIN & VTIME to 1/0 respectively
when (not cooked) $ do
then ioError (ioe_unk_error "setCooked" "failed to set buffering")
else return ()
+ioe_unk_error :: String -> String -> IOException
ioe_unk_error loc msg
= IOError Nothing OtherError loc msg Nothing
-- ---------------------------------------------------------------------------
-- Turning on non-blocking for a file descriptor
+setNonBlockingFD :: FD -> IO ()
#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
-
setNonBlockingFD fd = do
flags <- throwErrnoIfMinus1Retry "setNonBlockingFD"
(c_fcntl_read fd const_f_getfl)
#else
-- bogus defns for win32
-setNonBlockingFD fd = return ()
+setNonBlockingFD _ = return ()
#endif
foreign import ccall unsafe "HsBase.h chmod"
c_chmod :: CString -> CMode -> IO CInt
-foreign import ccall unsafe "HsBase.h chdir"
- c_chdir :: CString -> IO CInt
-
foreign import ccall unsafe "HsBase.h close"
c_close :: CInt -> IO CInt
foreign import ccall unsafe "HsBase.h __hscore_fstat"
c_fstat :: CInt -> Ptr CStat -> IO CInt
-foreign import ccall unsafe "HsBase.h getcwd"
- c_getcwd :: Ptr CChar -> CSize -> IO (Ptr CChar)
-
foreign import ccall unsafe "HsBase.h isatty"
c_isatty :: CInt -> IO CInt
foreign import ccall unsafe "HsBase.h read"
c_read :: CInt -> Ptr CChar -> CSize -> IO CSsize
-foreign import ccall unsafe "dirUtils.h __hscore_renameFile"
- c_rename :: CString -> CString -> IO CInt
-
foreign import ccall unsafe "HsBase.h rewinddir"
c_rewinddir :: Ptr CDir -> IO ()
-foreign import ccall unsafe "HsBase.h rmdir"
- c_rmdir :: CString -> IO CInt
-
foreign import ccall unsafe "HsBase.h __hscore_stat"
c_stat :: CString -> Ptr CStat -> IO CInt
foreign import ccall unsafe "HsBase.h __hscore_ptr_c_cc" ptr_c_cc :: Ptr CTermios -> IO (Ptr Word8)
#endif
-#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
-foreign import ccall unsafe "HsBase.h __hscore_s_issock" c_s_issock :: CMode -> CInt
s_issock :: CMode -> Bool
+#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
s_issock cmode = c_s_issock cmode /= 0
+foreign import ccall unsafe "HsBase.h __hscore_s_issock" c_s_issock :: CMode -> CInt
#else
-s_issock :: CMode -> Bool
-s_issock cmode = False
+s_issock _ = False
#endif