Skip to content
Snippets Groups Projects
Commit e16cfb55 authored by sof's avatar sof
Browse files

[project @ 1999-09-19 19:30:04 by sof]

* Re-exported IO.HandlePosn, i.e.,

         type HandlePosition = Integer
	 data HandlePosn = HandlePosn Handle HandlePosition

* Added hTell :: Handle -> HandlePosition
  (merely a wrapper for IO.hGetPosn )

* Added hSetBinaryMode :: Handle -> Bool -> IO Bool
  for dynamically changing the 'translation mode' of a Handle.
  This stuff is only useful on platforms that make a distinction
  between text and binary files (e.g., Win32)
parent 7bef35dc
No related branches found
No related tags found
No related merge requests found
......@@ -60,6 +60,12 @@ module IOExts
, unsafePtrEq
, freeHaskellFunctionPtr
, HandlePosition
, HandlePosn(..)
, hTell -- :: Handle -> IO HandlePosition
, hSetBinaryMode -- :: Handle -> Bool -> IO Bool
) where
......@@ -182,9 +188,12 @@ trace string expr = unsafePerformIO $ do
fd <- getHandleFd stderr
hPutStr stderr string
hPutChar stderr '\n'
_ccall_ PostTraceHook fd
postTraceHook fd
return expr
foreign import "PostTraceHook" postTraceHook :: Int -> IO ()
#endif
\end{code}
Not something you want to call normally, but useful
......@@ -192,10 +201,8 @@ in the cases where you do want to flush stuff out of
the heap or make sure you've got room enough
\begin{code}
#ifdef __HUGS__
#else
performGC :: IO ()
performGC = _ccall_GC_ performGC
#ifndef __HUGS__
foreign import "performGC" performGC :: IO ()
#endif
\end{code}
......@@ -264,3 +271,44 @@ withStdin h a = withHandleFor h stdin a
withStdout h a = withHandleFor h stdout a
withStderr h a = withHandleFor h stderr a
\end{code}
@hTell@ is the lower-level version of @hGetPosn@ - return the
position, without bundling it together with the handle itself:
\begin{code}
hTell :: Handle -> IO HandlePosition
hTell h = do
(HandlePosn _ x) <- hGetPosn h
return x
\end{code}
@hSetBinaryMode@ lets you change the translation mode for a handle.
On some platforms (e.g., Win32) a distinction is made between being in
'text mode' or 'binary mode', with the former terminating lines
by \r\n rather than just \n.
Debating the Winnitude or otherwise of such a scheme is less than
interesting -- it's there, so we have to cope.
A side-effect of calling @hSetBinaryMode@ is that the output buffer
(if any) is flushed prior to changing the translation mode.
\begin{code}
hSetBinaryMode :: Handle -> Bool -> IO Bool
hSetBinaryMode handle is_binary = do
-- is_binary = True => set translation mode to binary.
wantRWHandle "hSetBinaryMode" handle $ \ handle_ -> do
let fo = haFO__ handle_
rc <- setBinaryMode fo flg
if rc >= 0 then
return (int2Bool rc)
else
constructErrorAndFail "hSetBinaryMode"
where
flg | is_binary = 1
| otherwise = 0
int2Bool 0 = False
int2Bool _ = True
\end{code}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment