summaryrefslogtreecommitdiff
path: root/testsuite/tests/lib/IO/hDuplicateTo001.hs
blob: 5a1484a0128f36a906ac758dc76d0043212c3d9b (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
import GHC.Handle
import GHC.IOBase
import System.IO
import Control.Concurrent.MVar
import Data.Typeable
import qualified GHC.IO.FD as FD

main = do
   h <- openFile "tmp" WriteMode
   hDuplicateTo h stdout
   
   fdh <- getfd h
   fdstdout <- getfd stdout
   hPutStrLn stderr ("h: " ++ show (fdh /= fdstdout) ++ "\nstdout: " ++ show fdstdout)

   hClose h
   putStrLn "bla"


getfd h@(FileHandle _ mvar) = do
  withMVar mvar $ \h__@Handle__{haDevice=dev} ->
   case cast dev of
     Just fd -> return (FD.fdFD fd)
     Nothing -> error "getfd"