From 71982aa65725a2e630b3abdbb5f48e1abf1acf91 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 31 Mar 2015 14:41:59 -0700 Subject: std: Add a process::exit function This commit is an implementation of [RFC #1011][rfc] which adds an `exit` function to the standard library for immediately terminating the current process with a specified exit code. [rfc]: https://github.com/rust-lang/rfcs/pull/1011 --- src/libstd/sys/unix/os.rs | 4 ++++ src/libstd/sys/windows/c.rs | 1 + src/libstd/sys/windows/os.rs | 4 ++++ 3 files changed, 9 insertions(+) (limited to 'src/libstd/sys') diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index fab443feebd..2ff7eba5732 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -505,3 +505,7 @@ pub fn home_dir() -> Option { } } } + +pub fn exit(code: i32) -> ! { + unsafe { libc::exit(code as c_int) } +} diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs index b9be4eb6bf5..b930e35c064 100644 --- a/src/libstd/sys/windows/c.rs +++ b/src/libstd/sys/windows/c.rs @@ -433,6 +433,7 @@ extern "system" { TokenHandle: *mut libc::HANDLE) -> libc::BOOL; pub fn GetCurrentProcess() -> libc::HANDLE; pub fn GetStdHandle(which: libc::DWORD) -> libc::HANDLE; + pub fn ExitProcess(uExitCode: libc::UINT) -> !; } #[link(name = "userenv")] diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index 167db1e8ac2..cbbce7f8f0a 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -379,3 +379,7 @@ pub fn home_dir() -> Option { }, super::os2path).ok() }) } + +pub fn exit(code: i32) -> ! { + unsafe { libc::ExitProcess(code as libc::UINT) } +} -- cgit 1.4.1-3-g733a5