-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Documentation gap surrounding errno
#1644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The first line of the readme says (emphasis mine):
One can't bind something that doesn't exist, and on most platforms, If you don't want to use "Raw" bindings, then |
Whether |
This crate exposes Raw FFI bindings, nothing more, nothing less. If that's unclear, PRs welcome. |
I'm going to close this as there's no update in over 6 months. Feel free to send a PR if you're still interested in that, of course! |
Many resources like C99 standard (see 7.5 @ page 186), cppreference C docs, MSVC libc docs, GCC docs mention that to check I found small library https://github.com/lambda-fairy/rust-errno/ but it use Since If |
Hello, I can confirm that on December 2021 this bug still exists. On the linux version of the documentation there is no errno (and I'm assuming it doesn't exist in the code either). It has epoll_ctr(), which is also not available in most systems, but no errno. The libc crate is still broken on linux. errno is part of the linux and POSIX APIs. |
Note that Still, |
That also doesn't let you set |
Just to emphasise lucy's point above, there are quite a lot of standard C library interfaces which cannot correctly be used without the application first setting errno. Herre are some examples:
It's all very well limiting libc to "just FFI" but if the result is an interface that cannot be correctly be used by itself, that's a really unfortunate ergonomic outcome. |
The README for the
libc
crate says:This isn't true; it doesn't provide
errno
. There's a large hole in the documentation surrounding this, and it's really unclear to me (as someone who just wants to call somelibc
functions) what the correct solution is.Previous discussion: #47 .
The closest thing to a mention of
errno
in thelibc
crate is__errno_location
(https://doc.rust-lang.org/1.6.0/libc/fn.__errno_location.html), which has leading underscores and no documentation, suggesting that it's a private API which was exposed accidentally.The
std
crate hasstd::io::last_os_error
(https://doc.rust-lang.org/std/io/struct.Error.html#method.last_os_error), which is sort-of like errno, but not quite enough like errno to actually match up with anything you'd find in manpage. It hasstd::io::ErrorKind
(https://doc.rust-lang.org/std/io/enum.ErrorKind.html) which has error types which sound like common errnos, but if they're supposed to be the same, it has failed to document this, and it's not exhaustive. Also it's read-only, which is insufficient for many some libc functions, where the convention is to set errno to 0 before calling them.There's an
errno
crate, which provides both a getter and setter, but it's by a single developer rather than the rust core team, and there's no particular reason to trust its portability or long-term stability.There used to be a
std::os::errno
. It's gone, but ranks #2 in the Google search results for "rust errno" (https://www.reddit.com/r/rust/comments/31b9zw/is_stdoserrno_no_longer_available/). Just to rub it in.The
nix
crate (which depends onlibc
and provides lots of wrappers) hasnix::errno::errno
andnix::errno::from_i32
, which is what I've settled on for my own use. (Still readonly, and this bothers me from a soundness standpoint, but I can live with it). AFAICTnix
is not by the Rust core team, but at least it's widely used and appears maintained.Sorting through all this took a bunch of time, when all I really wanted was to call some familiar
libc
functions. I see a few possible options here:errno
getter and setter functions to thelibc
crate.std::io::last_os_error
results anderrno
, make it exhaustive, and leave a note in theREADME
saying that's where to go for errnos.README
to make it clear thatlibc
is not self-contained, but requires another crate (such aserrno
ornix
) to use correctly.The text was updated successfully, but these errors were encountered: