summaryrefslogtreecommitdiff
path: root/libraries/base/tests/IO/hDuplicateTo001.hs
blob: 99f956a0dff506ff226c54a92315257e2d2daf0a (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
import GHC.IO
import GHC.IO.Handle
import GHC.IO.Handle.Types
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"