I have been trying to get errno value from the libc. For some reason, the API available in https://github.com/rust-lang/libc is not present. (using libc = "0.2")
error[E0425]: cannot find function `___errno` in crate `libc`
--> src/main.rs:4:27
|
4 | println!("{}", *libc::___errno());
| ^^^^^^^^ not found in `libc`
Or you can write .unwrap_or(0) for a guaranteed-not-panicking unwrap, where 0 means "no error", since errno is guaranteed to be non-zeroin case of error (NB: two links).
libc::__errno_location() is an internal platform-specific function that exists on the major Linux libc implementations. It does not necessarily exist on other Unix-like operating systems, nor on Windows. (For instance, the same function is instead called __errno() on OpenBSD and __error() on macOS.) The best cross-platform way to get the value of errno is to use io::Error::last_os_error(), which is guaranteed to return an io::Error representing an OS error.