-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support Errno formatting in no_std #44
Conversation
src/wasi.rs
Outdated
let mut buf = [0 as c_char; 1024]; | ||
unsafe { | ||
let mut buf = [0u8; 1024]; | ||
let c_str = unsafe { | ||
if strerror_r(err.0, buf.as_mut_ptr(), buf.len() as libc::size_t) < 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error[E0308]: mismatched types
Error: --> src/wasi.rs:32:30
|
32 | if strerror_r(err.0, buf.as_mut_ptr(), buf.len() as libc::size_t) < 0 {
| ---------- ^^^^^^^^^^^^^^^^ expected `i8`, found `u8`
| |
| arguments to this function are incorrect
|
= note: expected raw pointer `*mut i8`
found raw pointer `*mut u8`
note: function defined here
--> src/wasi.rs:66:8
|
66 | fn strerror_r(errnum: c_int, buf: *mut c_char,
| ^^^^^^^^^^
Cargo.toml
Outdated
@@ -14,7 +14,8 @@ categories = ["no-std", "os"] | |||
libc = "0.2" | |||
|
|||
[target.'cfg(windows)'.dependencies] | |||
winapi = { version = "0.3", features = ["errhandlingapi", "minwindef"] } | |||
widestring = { version = "0.5.1", default-features = false } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
widestring
MSRV is 1.58.1.
We can bump up our MSRV as well, but I'm not sure what our users will think about that. For example, caps
and rustix
guarantee 1.36 and 1.48 respectively.
Is there an easy alternative we can use here?
cc @sunfishcode and @lucab
src/windows.rs
Outdated
#[cfg(feature = "std")] | ||
fn from_utf16_lossy<'a>(input: &[u16], output: &'a mut [u8]) -> &'a str { | ||
let mut output_len = 0; | ||
for c in UStr::from_slice(input).chars_lossy().take_while(|&x| x != '\0') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to use core::char::decode_utf16
here? To get lossy behavior, you can run it through .map(|r| r.unwrap_or(core::char::REPLACEMENT_CHARACTER))
.
If so, that would eliminated the need for the widestring
dependency, which would avoid the MSRV issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you @A1-Triard and @sunfishcode!
No description provided.