1 # errno [![CI](https://github.com/lambda-fairy/rust-errno/actions/workflows/main.yml/badge.svg)](https://github.com/lambda-fairy/rust-errno/actions/workflows/main.yml) [![Cargo](https://img.shields.io/crates/v/errno.svg)](https://crates.io/crates/errno)
3 Cross-platform interface to the [`errno`][errno] variable. Works on Rust 1.56 or newer.
5 Documentation is available at <https://docs.rs/errno>.
7 [errno]: https://en.wikipedia.org/wiki/Errno.h
12 Add to your `Cargo.toml`:
20 ## Comparison with `std::io::Error`
22 The standard library provides [`Error::last_os_error`][last_os_error] which fetches `errno` in the same way.
24 This crate provides these extra features:
27 - Optional `#![no_std]` support
28 - A `set_errno` function
30 [last_os_error]: https://doc.rust-lang.org/std/io/struct.Error.html#method.last_os_error
37 use errno::{Errno, errno, set_errno};
39 // Get the current value of errno
42 // Set the current value of errno
45 // Extract the error code as an i32
48 // Display a human-friendly error message
49 println!("Error {}: {}", code, e);
55 Enable `#![no_std]` support by disabling the default `std` feature:
59 errno = { version = "*", default-features = false }
62 The `Error` impl will be unavailable.