Skip to content

Commit 3094772

Browse files
committed
Make Errno::clear safe
All it does is assign a value to a thread-local int. There's nothing unsafe about that.
1 parent e6e25ec commit 3094772

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4848
`::nix::sys::reboot` now return `Result<Infallible>` instead of `Result<Void>` (#[1239](https://github.com/nix-rust/nix/pull/1239))
4949
- `sys::socket::sockaddr_storage_to_addr` is no longer `unsafe`. So is
5050
`offset_of!`.
51+
- `sys::socket::sockaddr_storage_to_addr`, `offset_of!`, and `Errno::clear` are
52+
no longer `unsafe`.
5153
(#[1244](https://github.com/nix-rust/nix/pull/1244))
5254
- Several `Inotify` methods now take `self` by value instead of by reference
5355
(#[1244](https://github.com/nix-rust/nix/pull/1244))

src/errno.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ cfg_if! {
4646
}
4747

4848
/// Sets the platform-specific errno to no-error
49-
unsafe fn clear() {
50-
*errno_location() = 0;
49+
fn clear() {
50+
// Safe because errno is a thread-local variable
51+
unsafe {
52+
*errno_location() = 0;
53+
}
5154
}
5255

5356
/// Returns the platform-specific value of errno
@@ -70,7 +73,7 @@ impl Errno {
7073
from_i32(err)
7174
}
7275

73-
pub unsafe fn clear() {
76+
pub fn clear() {
7477
clear()
7578
}
7679

0 commit comments

Comments
 (0)