diff options
| author | Barosl Lee <vcs@barosl.com> | 2014-11-12 02:50:44 +0900 |
|---|---|---|
| committer | Barosl Lee <vcs@barosl.com> | 2014-11-19 05:31:45 +0900 |
| commit | b5286af703e33bd36744fe4cd5bb24f71dbb524e (patch) | |
| tree | 65d05bc5f3b5d8777ca44f6b5687732c47629610 /src/libstd | |
| parent | 5de56b3ca1defd9206db8364ecef5f3fd8cc5b38 (diff) | |
| download | rust-b5286af703e33bd36744fe4cd5bb24f71dbb524e.tar.gz rust-b5286af703e33bd36744fe4cd5bb24f71dbb524e.zip | |
Make os::setenv() and os::unsetenv() panic if an error occurs
These functions can fail if: - EINVAL: The name is empty, or contains an '=' character - ENOMEM: Insufficient memory
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/os.rs | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/libstd/os.rs b/src/libstd/os.rs index cf22b8014ca..b898b9a2df4 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -422,7 +422,9 @@ pub fn setenv<T: BytesContainer>(n: &str, v: T) { with_env_lock(|| { n.with_c_str(|nbuf| { v.with_c_str(|vbuf| { - libc::funcs::posix01::unistd::setenv(nbuf, vbuf, 1); + if libc::funcs::posix01::unistd::setenv(nbuf, vbuf, 1) != 0 { + panic!(IoError::last_error()); + } }) }) }) @@ -438,7 +440,9 @@ pub fn setenv<T: BytesContainer>(n: &str, v: T) { unsafe { with_env_lock(|| { - libc::SetEnvironmentVariableW(n.as_ptr(), v.as_ptr()); + if libc::SetEnvironmentVariableW(n.as_ptr(), v.as_ptr()) == 0 { + panic!(IoError::last_error()); + } }) } } @@ -453,7 +457,9 @@ pub fn unsetenv(n: &str) { unsafe { with_env_lock(|| { n.with_c_str(|nbuf| { - libc::funcs::posix01::unistd::unsetenv(nbuf); + if libc::funcs::posix01::unistd::unsetenv(nbuf) != 0 { + panic!(IoError::last_error()); + } }) }) } @@ -465,11 +471,14 @@ pub fn unsetenv(n: &str) { n.push(0); unsafe { with_env_lock(|| { - libc::SetEnvironmentVariableW(n.as_ptr(), ptr::null()); + if libc::SetEnvironmentVariableW(n.as_ptr(), ptr::null()) == 0 { + panic!(IoError::last_error()); + } }) } } - _unsetenv(n); + + _unsetenv(n) } /// Parses input according to platform conventions for the `PATH` |
