System errors

The std::os::errno() started shouting at me that it’s deprecated. With slightly misleading warning that it should be replaced by functions from std::env which applies to most std::os but not this particular function.

The only replacement I could find is std::io::Error::last_os_error(), but it is not completely adequate, because it can only distinguish the IO-related errors. But I need values like E2BIG and EILSEQ. System-specific values are OK, because the function is system-specific too. Actually looking at the source it seems it carries the errno value along, but I see no way to get to it from the interface.

Is there any better replacement? Will the io::Error be extended or should there be another replacement?

1 Like

Yes we plan on allowing access of the error code within io::Error (this should happen soon). For now #[allow(deprecated)] on a small function should do the trick!

1 Like

I had your exact issue a few days ago!

I solved it by extracting the errno code into its own crate: https://crates.io/crates/errno

This should be a decent stop-gap, at least until the functionality is added back to std.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.