I wrote the following code in VS Code and ran it to set file attribute. It seemed to have run successfully, but when I checked the value, the text was not correct. Is Unicode string supported for file extended attributes? If so, how can I fix the code below?
#include <stdio.h>
#include <sys/xattr.h>
int main()
{
printf("ねこ\n");
ssize_t res = setxattr("/mnt/cat/test.txt", "user.dog"
, "ねこ", 2, 0); /*also tested 4 and 8*/
printf("Result = %lu\n", (unsigned long)res);
return 0;
}
Programme output
ねこ
Result = 0
Reading attribute
$ getfattr test.txt -d
# file: test.txt
user.dog=0s44E=