+% -----------------------------------------------------------------------------
+% $Id: System.lhs,v 1.27 2001/01/11 07:04:16 qrczak Exp $
%
-% (c) The AQUA Project, Glasgow University, 1994-1999
+% (c) The University of Glasgow, 1994-2000
%
\section[System]{Module @System@}
\begin{code}
import Prelude
import PrelAddr
-import PrelIOBase ( IOError(..), IOErrorType(..), constructErrorAndFailWithInfo, stToIO )
+import PrelIOBase ( IOException(..), ioException,
+ IOErrorType(..), constructErrorAndFailWithInfo, stToIO )
import PrelPack ( unpackCString, unpackCStringST, packString )
import PrelByteArr ( ByteArray )
litstring <- primGetEnv (primPackString name)
if litstring /= nullAddr
then primUnpackCString litstring
- else ioError (IOError Nothing NoSuchThing "getEnv"
- ("environment variable: " ++ name))
+ else ioException (IOError Nothing NoSuchThing "getEnv"
+ "no environment variable" (Just name))
foreign import ccall "libHS_cbits.so" "getenv" unsafe primGetEnv :: PrimByteArray -> IO Addr
\end{code}
\begin{code}
system :: String -> IO ExitCode
-system "" = ioError (IOError Nothing InvalidArgument "system" "null command")
+system "" = ioException (IOError Nothing InvalidArgument "system" "null command" Nothing)
system cmd = do
status <- primSystem (primPackString cmd)
case status of
exitWith :: ExitCode -> IO a
exitWith ExitSuccess = do
primExit 0
- ioError (IOError Nothing OtherError "exitWith" "exit should not return")
+ ioException (IOError Nothing OtherError "exitWith" "exit should not return" Nothing)
exitWith (ExitFailure n)
- | n == 0 = ioError (IOError Nothing InvalidArgument "exitWith" "ExitFailure 0")
+ | n == 0 = ioException (IOError Nothing InvalidArgument "exitWith" "ExitFailure 0" Nothing)
| otherwise = do
primExit n
- ioError (IOError Nothing OtherError "exitWith" "exit should not return")
+ ioException (IOError Nothing OtherError "exitWith" "exit should not return" Nothing)
--- SUP: Although shutdownHaskellAndExit is declared "unsafe" below, it *can*
--- re-enter Haskell land through finalizers. But this is probably not a problem,
--- because it never returns.
-foreign import ccall "shutdownHaskellAndExit" unsafe primExit :: Int -> IO ()
+-- NOTE: shutdownHaskellAndExit must be called "safe", because it *can*
+-- re-enter Haskell land through finalizers.
+foreign import ccall "shutdownHaskellAndExit" primExit :: Int -> IO ()
exitFailure :: IO a
exitFailure = exitWith (ExitFailure 1)
nh_stdout >>= nh_flush
nh_stdin >>= nh_close
nh_exitwith (fromExitCode c)
- (ioError.IOError) "System.exitWith: should not return"
+ (ioException . IOError) "System.exitWith: should not return"
system :: String -> IO ExitCode
system cmd
| null cmd
- = (ioError.IOError) "System.system: null command"
+ = (ioException.IOError) "System.system: null command"
| otherwise
= do str <- copy_String_to_cstring cmd
status <- nh_system str