-- #hide
module System.Posix.Internals where
-#include "HsBaseConfig.h"
+#ifndef __NHC__
+# include "HsBaseConfig.h"
+#endif
+#if ! (defined(mingw32_HOST_OS) || defined(__MINGW32__))
import Control.Monad
+#endif
import System.Posix.Types
import Foreign
import Data.Bits
import Data.Maybe
+#if !defined(HTYPE_TCFLAG_T)
+import System.IO.Error
+#endif
+
#if __GLASGOW_HASKELL__
import GHC.Base
import GHC.Num
#elif __HUGS__
import Hugs.Prelude (IOException(..), IOErrorType(..))
import Hugs.IO (IOMode(..))
-#else
+#elif __NHC__
import System.IO
+import Control.Exception
+import DIOError
#endif
#ifdef __HUGS__
if not (s_isreg c_mode)
then return (-1)
else do
- c_size <- st_size p_stat
- return (fromIntegral c_size)
+ c_size <- st_size p_stat
+ return (fromIntegral c_size)
data FDType = Directory | Stream | RegularFile | RawDevice
deriving (Eq)
| otherwise -> ioError ioe_unknownfiletype
ioe_unknownfiletype :: IOException
+#ifndef __NHC__
ioe_unknownfiletype = IOError Nothing UnsupportedOperation "fdType"
- "unknown file type" Nothing
+ "unknown file type"
+# if __GLASGOW_HASKELL__
+ Nothing
+# endif
+ Nothing
+#else
+ioe_unknownfiletype = UserError "fdType" "unknown file type"
+#endif
#if __GLASGOW_HASKELL__ && (defined(mingw32_HOST_OS) || defined(__MINGW32__))
closeFd :: Bool -> CInt -> IO CInt
#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
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
+#ifndef __NHC__
+ = ioeSetErrorString (mkIOError OtherError loc Nothing Nothing) msg
+#else
+ = UserError loc msg
+#endif
-- Note: echoing goes hand in hand with enabling 'line input' / raw-ness
-- for Win32 consoles, hence setEcho ends up being the inverse of setCooked.
-- ---------------------------------------------------------------------------
-- Turning on non-blocking for a file descriptor
-#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
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 __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