about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-03-31 15:58:57 -0700
committerAlex Crichton <alex@alexcrichton.com>2015-03-31 15:58:57 -0700
commita37311d486d5e71b2f2d1290c9f9228c4f6ead79 (patch)
tree21beece7faab89e01f8c58cf92f78ab0002fe4d1 /src/libstd/sys
parent0cac5b615811afeb634a73b86dcf0f1f51fe9aa8 (diff)
parent71982aa65725a2e630b3abdbb5f48e1abf1acf91 (diff)
downloadrust-a37311d486d5e71b2f2d1290c9f9228c4f6ead79.tar.gz
rust-a37311d486d5e71b2f2d1290c9f9228c4f6ead79.zip
rollup merge of #23907: alexcrichton/impl-exit
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

Closes #23914
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/unix/os.rs4
-rw-r--r--src/libstd/sys/windows/c.rs1
-rw-r--r--src/libstd/sys/windows/os.rs4
3 files changed, 9 insertions, 0 deletions
diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs
index af5b40af938..7b13e951b9b 100644
--- a/src/libstd/sys/unix/os.rs
+++ b/src/libstd/sys/unix/os.rs
@@ -506,3 +506,7 @@ pub fn home_dir() -> Option<PathBuf> {
         }
     }
 }
+
+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 ef153c7e845..f98c39cfad0 100644
--- a/src/libstd/sys/windows/os.rs
+++ b/src/libstd/sys/windows/os.rs
@@ -380,3 +380,7 @@ pub fn home_dir() -> Option<PathBuf> {
         }, super::os2path).ok()
     })
 }
+
+pub fn exit(code: i32) -> ! {
+    unsafe { libc::ExitProcess(code as libc::UINT) }
+}