2 % (c) The GRASP/AQUA Project, Glasgow University, 1995
4 \section[LibPosix]{Haskell 1.3 POSIX bindings}
32 -- make interface complete:
33 setCurrentDirectory{-pragmas-}, getCurrentDirectory{-pragmas-}
41 import LibPosixProcEnv
42 import LibPosixProcPrim
46 -- runProcess is our candidate for the high-level OS-independent primitive
47 -- If accepted, it will be moved out of LibPosix into LibSystem.
49 import LibDirectory ( setCurrentDirectory, getCurrentDirectory{-pragmas-} )
52 import PreludePrimIO ( takeMVar, putMVar, _MVar )
55 runProcess :: FilePath -- Command
56 -> [String] -- Arguments
57 -> Maybe [(String, String)] -- Environment
58 -> Maybe FilePath -- Working directory
59 -> Maybe Handle -- stdin
60 -> Maybe Handle -- stdout
61 -> Maybe Handle -- stderr
63 runProcess path args env dir stdin stdout stderr =
64 forkProcess >>= \ pid ->
66 Nothing -> doTheBusiness
69 doTheBusiness :: IO ()
71 maybeChangeWorkingDirectory >>
75 executeFile path True args env >>
78 maybeChangeWorkingDirectory :: IO ()
79 maybeChangeWorkingDirectory =
82 Just x -> setCurrentDirectory x
84 maybeDup2 :: Int -> Maybe Handle -> IO ()
86 case h of Nothing -> return ()
87 Just x -> handleFD x >>= \ src ->
88 dupChannelTo src dest >>
91 handleFD :: Handle -> IO Channel
93 takeMVar handle >>= \ htype ->
94 putMVar handle htype >>
96 _ErrorHandle ioError -> failWith ioError
97 _ClosedHandle -> failWith (IllegalOperation "handle is closed")
98 _SemiClosedHandle _ _ -> failWith (IllegalOperation "handle is closed")
100 _casm_ ``%r = fileno((FILE *)%0);'' (_filePtr other)