On Wed, Feb 12, 2025 at 2:13 PM Kevin Wolf <kw...@redhat.com> wrote: > Yes, we definitely need some proper bindings there. I'm already tired of > writing things like this: > > return -(bindings::EINVAL as std::os::raw::c_int) > > Or even: > > return e > .raw_os_error() > .unwrap_or(-(bindings::EIO as std::os::raw::c_int))
This by the way seemed incorrect to me as it should be return -(e .raw_os_error() .unwrap_or(bindings::EIO as std::os::raw::c_int)) (leaving aside that raw_os_error does not work on Windows)... But then I noticed that read_raw() also does not negate, which causes the error to print incorrectly... > Which actually already shows that your errno binding patch does the > opposite direction of what I needed in this series. ... so my patch already helps a bit: you can still change if ret < 0 { Err(Error::from_raw_os_error(ret)) } else { Ok(()) } to errno::into_io_result(ret)?; Ok(()) and avoid the positive/negative confusion. Anyhow, I guess the first one wouldn't be much better: return errno::into_negative_errno(ErrorKind::InvalidInput); whereas the second could be return errno::into_negative_errno(e); But then the first is already a special case; it only happens where your bindings are not trivial thanks to the introduction of the Mapping type. Paolo > My problem is when I > need to return an int to C, and I either have an io::Result or I just > want to directly return an errno value. So we'll have to add that part > to your errno module, too.