Skip to content

Commit 44e1e4d

Browse files
committed
use posix error message for unix
1 parent 61895e3 commit 44e1e4d

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

  • crates/vm/src/stdlib

crates/vm/src/stdlib/io.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,18 @@ impl ToPyException for std::io::Error {
3939
}
4040
self.to_string()
4141
};
42-
#[cfg(not(windows))]
42+
#[cfg(unix)]
43+
let msg = {
44+
let ptr = unsafe { libc::strerror(errno) };
45+
if !ptr.is_null() {
46+
unsafe { std::ffi::CStr::from_ptr(ptr) }
47+
.to_string_lossy()
48+
.into_owned()
49+
} else {
50+
self.to_string()
51+
}
52+
};
53+
#[cfg(not(any(windows, unix)))]
4354
let msg = self.to_string();
4455

4556
#[allow(clippy::let_and_return)]

0 commit comments

Comments
 (0)