summaryrefslogtreecommitdiff
path: root/testsuite/tests/ghc-regress/lib/libposix/posix012.hs
blob: 87f002a6cd901dae87adbe4a90efdefbda0eb4a7 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import Posix
import IO -- 1.3

main =
    createFile "po012.out" stdFileMode >>= \ fd ->
    installHandler processStatusChanged (Catch (reap1 fd)) Nothing >>
    ls >>
    awaitSignal Nothing

ls =
    runProcess "ls" ["-l"] Nothing Nothing Nothing Nothing Nothing

reap1 fd =
    hPutStrLn stderr "Reaper1"         >>
    getAnyProcessStatus True False     >>
    installHandler processStatusChanged (Catch (reap2 fd)) Nothing >>
    fdWrite fd (take 666 (repeat 'x')) >>
    ls                                 >>
    awaitSignal Nothing
    
reap2 fd =
    hPutStrLn stderr "Reaper2"     >>
    getAnyProcessStatus True False >>
    installHandler processStatusChanged (Catch (reap3 fd)) Nothing >>
    setFileMode "po012.out" 
	(foldr1 unionFileModes [ownerReadMode,ownerWriteMode,groupReadMode,otherReadMode]) >>
    ls >>
    awaitSignal Nothing
    
reap3 fd =
    hPutStrLn stderr "Reaper3"     >>
    getAnyProcessStatus True False >>
    installHandler processStatusChanged (Catch (reap4 fd)) Nothing >>
    setFileTimes "po012.out" 0 0 >>
    ls >>
    awaitSignal Nothing
    
reap4 fd =
    hPutStrLn stderr "Reaper4"     >>
    getAnyProcessStatus True False >>
    installHandler processStatusChanged (Catch (reap5 fd)) Nothing >>
    --removeLink "po012.out" >>
    ls >>
    awaitSignal Nothing

reap5 fd =
    hPutStrLn stderr "Reaper5"     >>
    getAnyProcessStatus True False >>
    fdSeek fd SeekFromEnd 0        >>= \ bytes ->
    if bytes == 666 then
	fdSeek fd AbsoluteSeek 0   >>
	hPutStrLn stderr "Reaper5"     >>
	fdRead fd 666             >>= \ (str, _) ->
	if str == (take 666 (repeat 'x')) then
	    putStr "Okay\n"
	else
	    putStr "Read failed\n"
    else
	putStr "Seek returned wrong size\n"