summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Somers <asomers@gmail.com>2020-05-16 17:34:33 -0600
committerAlan Somers <asomers@gmail.com>2020-06-27 17:36:46 -0600
commit309477210c8be94f7015904fd556f70bf26c0198 (patch)
tree6020c737ac820e951040f48afcb3407ce925a28b
parente6e25ec8cac2635b556355ec6a00bc1cc8d4fa6e (diff)
downloadnix-309477210c8be94f7015904fd556f70bf26c0198.zip
Make Errno::clear safe
All it does is assign a value to a thread-local int. There's nothing unsafe about that.
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/errno.rs9
2 files changed, 8 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6b58beb1..41cb121c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -48,6 +48,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
`::nix::sys::reboot` now return `Result<Infallible>` instead of `Result<Void>` (#[1239](https://github.com/nix-rust/nix/pull/1239))
- `sys::socket::sockaddr_storage_to_addr` is no longer `unsafe`. So is
`offset_of!`.
+- `sys::socket::sockaddr_storage_to_addr`, `offset_of!`, and `Errno::clear` are
+ no longer `unsafe`.
(#[1244](https://github.com/nix-rust/nix/pull/1244))
- Several `Inotify` methods now take `self` by value instead of by reference
(#[1244](https://github.com/nix-rust/nix/pull/1244))
diff --git a/src/errno.rs b/src/errno.rs
index 1fb66ac5..eda097d8 100644
--- a/src/errno.rs
+++ b/src/errno.rs
@@ -46,8 +46,11 @@ cfg_if! {
}
/// Sets the platform-specific errno to no-error
-unsafe fn clear() {
- *errno_location() = 0;
+fn clear() {
+ // Safe because errno is a thread-local variable
+ unsafe {
+ *errno_location() = 0;
+ }
}
/// Returns the platform-specific value of errno
@@ -70,7 +73,7 @@ impl Errno {
from_i32(err)
}
- pub unsafe fn clear() {
+ pub fn clear() {
clear()
}