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
This commit is contained in:
Alex Crichton
2015-03-31 14:41:59 -07:00
parent 80bf31dd51
commit 71982aa657
5 changed files with 56 additions and 0 deletions

View File

@@ -505,3 +505,7 @@ pub fn home_dir() -> Option<PathBuf> {
}
}
}
pub fn exit(code: i32) -> ! {
unsafe { libc::exit(code as c_int) }
}

View File

@@ -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")]

View File

@@ -379,3 +379,7 @@ pub fn home_dir() -> Option<PathBuf> {
}, super::os2path).ok()
})
}
pub fn exit(code: i32) -> ! {
unsafe { libc::ExitProcess(code as libc::UINT) }
}