[project @ 2005-04-22 16:07:36 by sof]
[ghc-base.git] / GHC / Handle.hs
index 2ea5c38..f3008c4 100644 (file)
@@ -17,6 +17,7 @@
 --
 -----------------------------------------------------------------------------
 
+-- #hide
 module GHC.Handle (
   withHandle, withHandle', withHandle_,
   wantWritableHandle, wantReadableHandle, wantSeekableHandle,
@@ -75,6 +76,9 @@ import GHC.Enum
 import GHC.Num         ( Integer(..), Num(..) )
 import GHC.Show
 import GHC.Real                ( toInteger )
+#if defined(DEBUG_DUMP)
+import GHC.Pack
+#endif
 
 import GHC.Conc
 
@@ -511,7 +515,7 @@ fillReadBufferWithoutBlocking fd is_stream
   -- buffer better be empty:
   assert (r == 0 && w == 0) $ do
 #ifdef DEBUG_DUMP
-  puts ("fillReadBufferLoopNoBlock: bytes = " ++ show bytes ++ "\n")
+  puts ("fillReadBufferLoopNoBlock: bytes = " ++ show size ++ "\n")
 #endif
   res <- readRawBufferNoBlock "fillReadBuffer" fd is_stream b
                       0 (fromIntegral size)
@@ -1207,6 +1211,8 @@ hSetBuffering handle mode =
        -- 'raw' mode under win32 is a bit too specialised (and troublesome
        -- for most common uses), so simply disable its use here.
                  NoBuffering -> setCooked (haFD handle_) False
+#else
+                 NoBuffering -> return ()
 #endif
                  _           -> setCooked (haFD handle_) True
 
@@ -1535,10 +1541,10 @@ dupHandle other_side h_ = do
                c_dup (fromIntegral (haFD h_))
   dupHandle_ other_side h_ new_fd
 
-dupHandleTo other_side h_ hto_ = do
+dupHandleTo other_side hto_ h_ = do
   flushBuffer h_
   new_fd <- throwErrnoIfMinus1 "dupHandleTo" $ 
-               c_dup2 (fromIntegral (haFD hto_)) (fromIntegral (haFD h_))
+               c_dup2 (fromIntegral (haFD h_)) (fromIntegral (haFD hto_))
   dupHandle_ other_side h_ new_fd
 
 dupHandle_ other_side h_ new_fd = do
@@ -1627,10 +1633,10 @@ showHandle' filepath is_duplex h =
 -- ---------------------------------------------------------------------------
 -- debugging
 
-#ifdef DEBUG_DUMP
+#if defined(DEBUG_DUMP)
 puts :: String -> IO ()
-puts s = withCString s $ \cstr -> do write_rawBuffer 1 False cstr 0 (fromIntegral (length s))
-                                    return ()
+puts s = do write_rawBuffer 1 (unsafeCoerce# (packCString# s)) 0 (fromIntegral (length s))
+           return ()
 #endif
 
 -- -----------------------------------------------------------------------------