I am trying to implement Rusty wrappers for those extended attributes syscalls, if they are guaranteed to be UTF-8 encoded, then I can use the type String
, or I have to use OsString
.
I googled a lot, but only found these two pages:
freedesktop: CommonExtendedAttributes says that: Attribute strings should be in UTF-8 encoding.
macOS man page for
setxattr(2)
says that: The extended attribute names are simple NULL-terminated UTF-8 stringsSeems that this tells us the
name
is guaranteed to be UTF-8 encoded on macOS,
I would like to know information on as many platforms as possible since I try to cover them all in my implementation.
CodePudding user response:
No, in Linux they are absolutely not guaranteed to be in UTF-8. Attribute values are not even guaranteed to be strings at all. They are just arrays of bytes with no constraints on them.
int setxattr(const char *path, const char *name,
const void *value, size_t size, int flags);
const void *value, size_t size
is not a good way to pass a string to a function. const char* name
is, and attribute names are indeed strings, but they are null-terminated byte strings.
Freedesktop recommendations are just that, recommendations. They don't prevent anyone from creating any attribute they want.