summaryrefslogtreecommitdiff
path: root/ghc/tests/lib/IO/readwrite001.hs
blob: ebd80cf0802b33c0799474f47b7328fbe9cf39dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
-- !!! RW files 
module Main(main) where

import IO
import Directory ( removeFile, doesFileExist )
import Monad
#if defined(__MINGW32__)
import PrelHandle(hSetBinaryMode)
#endif

main = do
  f <- doesFileExist "readwrite001.inout" 
  when f (removeFile "readwrite001.inout")
  hdl <- openFile "readwrite001.inout" ReadWriteMode
# if defined(__MINGW32__)
  hSetBinaryMode hdl True
# endif
  hSetBuffering hdl LineBuffering
  hPutStr hdl "as"
  hSeek hdl AbsoluteSeek 0
  ch <- hGetChar hdl
  print ch
  hPutStr hdl "ase"
  hSeek hdl AbsoluteSeek 0
  putChar '\n'
  ls <- hGetContents hdl
  putStrLn ls