_ -> True
#ifdef mingw32_HOST_OS
- let _ = (dev,ino,write,fd) -- warning suppression
+ setmode fd True -- unconditionally set binary mode
+ let _ = (dev,ino,write) -- warning suppression
#endif
case fd_type of
},
fd_type)
+#ifdef mingw32_HOST_OS
+foreign import ccall unsafe "__hscore_setmode"
+ setmode :: CInt -> Bool -> IO CInt
+#endif
+
-- -----------------------------------------------------------------------------
-- Standard file descriptors
stdin :: Handle
stdin = unsafePerformIO $ do
-- ToDo: acquire lock
+ setBinaryMode FD.stdin
mkHandle FD.stdin "<stdin>" ReadHandle True (Just localeEncoding)
nativeNewlineMode{-translate newlines-}
(Just stdHandleFinalizer) Nothing
stdout :: Handle
stdout = unsafePerformIO $ do
-- ToDo: acquire lock
+ setBinaryMode FD.stdout
mkHandle FD.stdout "<stdout>" WriteHandle True (Just localeEncoding)
nativeNewlineMode{-translate newlines-}
(Just stdHandleFinalizer) Nothing
stderr :: Handle
stderr = unsafePerformIO $ do
-- ToDo: acquire lock
+ setBinaryMode FD.stderr
mkHandle FD.stderr "<stderr>" WriteHandle False{-stderr is unbuffered-}
(Just localeEncoding)
nativeNewlineMode{-translate newlines-}
flushWriteBuffer h_
putMVar m (ioe_finalizedHandle fp)
+-- We have to put the FDs into binary mode on Windows to avoid the newline
+-- translation that the CRT IO library does.
+setBinaryMode :: FD -> IO ()
+#ifdef mingw32_HOST_OS
+setBinaryMode fd = do setmode (fdFD fd) True; return ()
+#else
+setBinaryMode _ = return ()
+#endif
+
+#ifdef mingw32_HOST_OS
+foreign import ccall unsafe "__hscore_setmode"
+ setmode :: CInt -> Bool -> IO CInt
+#endif
+
-- ---------------------------------------------------------------------------
-- isEOF