The following is always meeting the ENOENT condition at the end. I would like to print ENODATA. What do I need to change in setxattr?
#include <sys/xattr.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
int main() {
int ret;
const char * file = "non_existent_file.txt";
const char * name = "user.test";
const char * value = "value";
ssize_t size = strlen(value);
printf("Setting Xattr\n");
ret = setxattr(file, name, value, size, XATTR_REPLACE);
if (ret == -1) {
printf("Xattr set failed: %s\n", strerror(errno));
perror("");
}
if (errno == ENODATA) {
printf("ENODATA\n");
}
if (errno == ENOENT) {
printf("ENOENT\n");
}
return 0;
}
I get “ENOENT” printed from last condition end statements
I tried adding the XATTR_REPLACE flag. I’ve removed valid paths for the file path
Edit:
Target OS: Ubuntu/ Linux