put 'unsafeCoerce' in a standard location
[haskell-directory.git] / GHC / IO.hs
index 37e0d67..14a6696 100644 (file)
--- a/GHC/IO.hs
+++ b/GHC/IO.hs
@@ -90,7 +90,7 @@ hWaitForInput h msecs = do
                writeIORef ref buf'
                return True
        else do r <- throwErrnoIfMinus1Retry "hWaitForInput" $
-                       inputReady (fromIntegral (haFD handle_)) 
+                       inputReady (haFD handle_)
                           (fromIntegral msecs) (haIsStream handle_)
                return (r /= 0)
 
@@ -132,7 +132,7 @@ hGetChar handle =
     NoBuffering -> do
        -- make use of the minimal buffer we already have
        let raw = bufBuf buf
-       r <- readRawBuffer "hGetChar" (fromIntegral fd) (haIsStream handle_) raw 0 1
+       r <- readRawBuffer "hGetChar" fd (haIsStream handle_) raw 0 1
        if r == 0
           then ioe_EOF
           else do (c,_) <- readCharFromBuffer raw 0
@@ -186,17 +186,17 @@ hGetLineBuffered handle_ = do
 
 hGetLineBufferedLoop :: Handle__ -> IORef Buffer -> Buffer -> [String]
                      -> IO String
-hGetLineBufferedLoop handle_ ref 
-       buf@Buffer{ bufRPtr=r, bufWPtr=w, bufBuf=raw } xss =
-  let 
-       -- find the end-of-line character, if there is one
-       loop raw r
-          | r == w = return (False, w)
-          | otherwise =  do
-               (c,r') <- readCharFromBuffer raw r
-               if c == '\n' 
-                  then return (True, r) -- NB. not r': don't include the '\n'
-                  else loop raw r'
+hGetLineBufferedLoop handle_ ref
+        buf@Buffer{ bufRPtr=r, bufWPtr=w, bufBuf=raw } xss =
+  let
+        -- find the end-of-line character, if there is one
+        loop raw r
+           | r == w = return (False, w)
+           | otherwise =  do
+                (c,r') <- readCharFromBuffer raw r
+                if c == '\n'
+                   then return (True, r) -- NB. not r': don't include the '\n'
+                   else loop raw r'
   in do
   (eol, off) <- loop raw r
 
@@ -209,24 +209,24 @@ hGetLineBufferedLoop handle_ ref
   -- if eol == True, then off is the offset of the '\n'
   -- otherwise off == w and the buffer is now empty.
   if eol
-       then do if (w == off + 1)
-                       then writeIORef ref buf{ bufRPtr=0, bufWPtr=0 }
-                       else writeIORef ref buf{ bufRPtr = off + 1 }
-               return (concat (reverse (xs:xss)))
-       else do
-            maybe_buf <- maybeFillReadBuffer (haFD handle_) True (haIsStream handle_)
-                               buf{ bufWPtr=0, bufRPtr=0 }
-            case maybe_buf of
-               -- Nothing indicates we caught an EOF, and we may have a
-               -- partial line to return.
-               Nothing -> do
-                    writeIORef ref buf{ bufRPtr=0, bufWPtr=0 }
-                    let str = concat (reverse (xs:xss))
-                    if not (null str)
-                       then return str
-                       else ioe_EOF
-               Just new_buf -> 
-                    hGetLineBufferedLoop handle_ ref new_buf (xs:xss)
+        then do if (w == off + 1)
+                        then writeIORef ref buf{ bufRPtr=0, bufWPtr=0 }
+                        else writeIORef ref buf{ bufRPtr = off + 1 }
+                return (concat (reverse (xs:xss)))
+        else do
+             maybe_buf <- maybeFillReadBuffer (haFD handle_) True (haIsStream handle_)
+                                buf{ bufWPtr=0, bufRPtr=0 }
+             case maybe_buf of
+                -- Nothing indicates we caught an EOF, and we may have a
+                -- partial line to return.
+                Nothing -> do
+                     writeIORef ref buf{ bufRPtr=0, bufWPtr=0 }
+                     let str = concat (reverse (xs:xss))
+                     if not (null str)
+                        then return str
+                        else ioe_EOF
+                Just new_buf ->
+                     hGetLineBufferedLoop handle_ ref new_buf (xs:xss)
 
 
 maybeFillReadBuffer fd is_line is_stream buf
@@ -350,7 +350,7 @@ lazyRead' h handle_ = do
      NoBuffering      -> do
        -- make use of the minimal buffer we already have
        let raw = bufBuf buf
-       r <- readRawBuffer "lazyRead" (fromIntegral fd) (haIsStream handle_) raw 0 1
+       r <- readRawBuffer "lazyRead" fd (haIsStream handle_) raw 0 1
        if r == 0
           then do handle_ <- hClose_help handle_ 
                   return (handle_, "")
@@ -413,7 +413,7 @@ hPutChar handle c = do
        BlockBuffering _ -> hPutcBuffered handle_ False c
        NoBuffering      ->
                with (castCharToCChar c) $ \buf -> do
-                 writeRawBufferPtr "hPutChar" (fromIntegral fd) (haIsStream handle_) buf 0 1
+                 writeRawBufferPtr "hPutChar" fd (haIsStream handle_) buf 0 1
                  return ()
 
 hPutcBuffered handle_ is_line c = do
@@ -718,7 +718,7 @@ writeChunk fd is_stream ptr bytes = loop 0 bytes
   loop _   bytes | bytes <= 0 = return ()
   loop off bytes = do
     r <- fromIntegral `liftM`
-          writeRawBufferPtr "writeChunk" (fromIntegral fd) is_stream ptr
+          writeRawBufferPtr "writeChunk" fd is_stream ptr
                             off (fromIntegral bytes)
     -- write can't return 0
     loop (off + r) (bytes - r)
@@ -730,7 +730,7 @@ writeChunkNonBlocking fd is_stream ptr bytes = loop 0 bytes
   loop off bytes | bytes <= 0 = return off
   loop off bytes = do
 #ifndef mingw32_HOST_OS
-    ssize <- c_write (fromIntegral fd) (ptr `plusPtr` off) (fromIntegral bytes)
+    ssize <- c_write fd (ptr `plusPtr` off) (fromIntegral bytes)
     let r = fromIntegral ssize :: Int
     if (r == -1)
       then do errno <- getErrno
@@ -739,7 +739,8 @@ writeChunkNonBlocking fd is_stream ptr bytes = loop 0 bytes
                 else throwErrno "writeChunk"
       else loop (off + r) (bytes - r)
 #else
-    (ssize, rc) <- asyncWrite fd (fromIntegral $ fromEnum is_stream)
+    (ssize, rc) <- asyncWrite (fromIntegral fd)
+                              (fromIntegral $ fromEnum is_stream)
                                 (fromIntegral bytes)
                                 (ptr `plusPtr` off)
     let r = fromIntegral ssize :: Int
@@ -823,7 +824,7 @@ readChunk fd is_stream ptr bytes = loop 0 bytes
   loop off bytes | bytes <= 0 = return off
   loop off bytes = do
     r <- fromIntegral `liftM`
-           readRawBufferPtr "readChunk" (fromIntegral fd) is_stream 
+           readRawBufferPtr "readChunk" fd is_stream 
                            (castPtr ptr) off (fromIntegral bytes)
     if r == 0
        then return off
@@ -904,7 +905,7 @@ bufReadNonBlocking fd ref is_stream ptr so_far count =
 readChunkNonBlocking :: FD -> Bool -> Ptr a -> Int -> IO Int
 readChunkNonBlocking fd is_stream ptr bytes = do
 #ifndef mingw32_HOST_OS
-    ssize <- c_read (fromIntegral fd) (castPtr ptr) (fromIntegral bytes)
+    ssize <- c_read fd (castPtr ptr) (fromIntegral bytes)
     let r = fromIntegral ssize :: Int
     if (r == -1)
       then do errno <- getErrno
@@ -914,7 +915,7 @@ readChunkNonBlocking fd is_stream ptr bytes = do
       else return r
 #else
     fromIntegral `liftM`
-        readRawBufferPtr "readChunkNonBlocking" (fromIntegral fd) is_stream 
+        readRawBufferPtr "readChunkNonBlocking" fd is_stream 
                            (castPtr ptr) 0 (fromIntegral bytes)
 
     -- we don't have non-blocking read support on Windows, so just invoke