-
Notifications
You must be signed in to change notification settings - Fork 167
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
Painful [i8] in rustix::fs::listxattr() #1218
Comments
Another wish item if we're going to break/add API here: |
|
Fixed in 0.38.41, thanks! |
How was it fixed? I can't find any mention of it being fixed and for me it's still taking in |
I think it wasn't actually fixed indeed. It started working at some point for me, but I think something else must have changed because a colleague was still running into the problem. |
#945 is relevant. It seems that the definition of |
listxattr()
is defined:which seems reasonable enough. It's
c_char
under there, of course. Unfortunately, at least on my platform (x86_64) this type is equivalent to&mut [i8]
which is a bit more of an oddity.The issue here is that there are an awful lot of APIs for converting between string types in Rust, and pretty much none of them consider
[i8]
as a string representation.In particular: the
name
field ofrustix::fs::getxattr()
wants a&CStr
. I'm not sure of a good way to get from one to the other.The core slice type has
split_inclusive()
which is a very nice way to iterate the returned values. You get the string plus the nul terminator, which you can then pass toCStr:from_bytes_with_nul
.... if it were a[u8]
slice.But since it's
[i8]
you end up having to do an unsafe transmute or an extremely explicit character-by-character conversion.Of course, because of the embedded nuls, this API can't return
CString
. But how about some variant of[u8]
instead?The text was updated successfully, but these errors were encountered: