-{-# OPTIONS -fno-implicit-prelude -#include "HsBase.h" #-}
+{-# OPTIONS_GHC -fno-implicit-prelude -#include "HsBase.h" #-}
#undef DEBUG_DUMP
--
-----------------------------------------------------------------------------
+-- #hide
module GHC.IO (
hWaitForInput, hGetChar, hGetLine, hGetContents, hPutChar, hPutStr,
commitBuffer', -- hack, see below
memcpy_baoff_ptr,
) where
-#include "config.h"
-
import Foreign
import Foreign.C
import GHC.List
import GHC.Exception ( ioError, catch )
-#ifdef mingw32_TARGET_OS
+#ifdef mingw32_HOST_OS
import GHC.Conc
#endif
(fromIntegral msecs) (haIsStream handle_)
return (r /= 0)
-foreign import ccall unsafe "inputReady"
+foreign import ccall safe "inputReady"
inputReady :: CInt -> CInt -> Bool -> IO CInt
-- ---------------------------------------------------------------------------
-- * 'isPermissionError' if another system resource limit would be exceeded.
hPutChar :: Handle -> Char -> IO ()
-hPutChar handle c =
- c `seq` do -- must evaluate c before grabbing the handle lock
+hPutChar handle c = do
+ c `seq` return ()
wantWritableHandle "hPutChar" handle $ \ handle_ -> do
let fd = haFD handle_
case haBufferMode handle_ of
loop :: Int -> Int -> IO Int
loop off bytes | bytes <= 0 = return off
loop off bytes = do
-#ifndef mingw32_TARGET_OS
+#ifndef mingw32_HOST_OS
ssize <- c_write (fromIntegral fd) (ptr `plusPtr` off) (fromIntegral bytes)
let r = fromIntegral ssize :: Int
if (r == -1)
readChunkNonBlocking :: FD -> Bool -> Ptr a -> Int -> IO Int
readChunkNonBlocking fd is_stream ptr bytes = do
-#ifndef mingw32_TARGET_OS
+#ifndef mingw32_HOST_OS
ssize <- c_read (fromIntegral fd) (castPtr ptr) (fromIntegral bytes)
let r = fromIntegral ssize :: Int
if (r == -1)
else throwErrno "readChunk"
else return r
#else
- (ssize, rc) <- asyncRead fd (fromIntegral $ fromEnum is_stream)
- (fromIntegral bytes) ptr
- let r = fromIntegral ssize :: Int
- if r == (-1)
- then ioError (errnoToIOError "hGetBufNonBlocking" (Errno (fromIntegral rc)) Nothing Nothing)
- else return r
+ fromIntegral `liftM`
+ readRawBufferPtr "readChunkNonBlocking" (fromIntegral fd) is_stream
+ (castPtr ptr) 0 (fromIntegral bytes)
+
+ -- we don't have non-blocking read support on Windows, so just invoke
+ -- the ordinary low-level read which will block until data is available,
+ -- but won't wait for the whole buffer to fill.
#endif
slurpFile :: FilePath -> IO (Ptr (), Int)