Repository navigation
Add a non-panic API for converting raw integers to Errno. - #1738
Open
sunfishcode wants to merge 2 commits into
Open
sunfishcode wants to merge 2 commits into
sunfishcode wants to merge 2 commits into
Conversation
Add an `Errno::try_from_raw_os_error` function, as a non-panicking version of `Errno::from_raw_os_error`. While here, fix the range check in `Errno::from_raw_os_error` to correctly check the full range of disallowed values.
|
I think Separately, |
stepancheg
reviewed
Nov 13, 2026
| #[inline] | ||
| pub const fn try_from_raw_os_error(raw: i32) -> Option<Self> { | ||
| // Unlike the linux_raw backend, we don't know the range of errno | ||
| // values that libc might use, so we assume any value is valid. |
There was a problem hiding this comment.
We know zero is not valid:
No function in this volume of POSIX.1-2024 shall set errno to 0.
https://pubs.opengroup.org/onlinepubs/9799919799/functions/errno.html
Similarly, C spec:
library functions never store 0 in errno
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add an
Errno::try_from_raw_os_errorfunction, as a non-panicking version ofErrno::from_raw_os_error.While here, fix the range check in
Errno::from_raw_os_errorto correctly check the full range of disallowed values.