@@ -1,5 +1,7 @@
1module System
1module System
3%include C "unistd.h"
5%include C "unistd.h"
4%default partial
6%default partial
5%access public export
7%access public export
@@ -52,11 +54,41 @@ getEnvironment = getAllPairs 0 []
52 then pure $ reverse $ map splitEq acc
54 then pure $ reverse $ map splitEq acc
53 else getAllPairs (n + 1) (envPair :: acc)
55 else getAllPairs (n + 1) (envPair :: acc)
57+||| Programs can either terminate successfully, or end in a caught
59+data ExitCode : Type where
60+ ||| Terminate successfully.
61+ ExitSuccess : ExitCode
62+ ||| Program terminated for some prescribed reason.
64+ ||| @errNo A non-zero numerical value indicating failure.
65+ ||| @prf Proof that the int value is non-zero.
66+ ExitFailure : (errNo : Int)
67+ -> {auto prf : So (not $ errNo == 0)}
55||| Quit with a particular exit code
70||| Quit with a particular exit code
56−exit : Int -> IO ()
71+exit : Int -> IO a
57−exit code = foreign FFI_C "exit" (Int -> IO ()) code
72+exit code = believe_me $ foreign FFI_C "exit" (Int -> IO ()) code
74+||| Terminate the program with an `ExitCode`. This code indicates the
75+||| success of the program's execution, and returns the success code
76+||| to the program's caller.
78+||| @code The `ExitCode` for program.
79+exitWith : (code : ExitCode) -> IO a
80+exitWith ExitSuccess = exit 0
81+exitWith (ExitFailure errNo) = exit errNo
83+||| Exit the program indicating failure.
85+exitFailure = exitWith (ExitFailure 1)
87+||| Exit the program after a successful run.
89+exitSuccess = exitWith ExitSuccess
59−||| Get the numbers of seconds since 1st January 1970, 00:00 UTC
91+||| Get the numbers of seconds since 1st January 1970, 00:00 UTC
60time : IO Integer
92time : IO Integer
61time = do MkRaw t <- foreign FFI_C "idris_time" (IO (Raw Integer))
93time = do MkRaw t <- foreign FFI_C "idris_time" (IO (Raw Integer))
@@ -66,4 +98,3 @@ usleep i = foreign FFI_C "usleep" (Int -> IO ()) i
67system : String -> IO Int
99system : String -> IO Int
68system cmd = foreign FFI_C "system" (String -> IO Int) cmd
100system cmd = foreign FFI_C "system" (String -> IO Int) cmd