#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char **argv) {
if(argc < 3) {
fprintf(stderr, "Usage: %s <file> <attribute>\n", argv[0]);
return -1;
}
int file = open(argv[1], O_RDONLY);
if(file == -1) {
fprintf(stderr, "Cannot open file ''%s'': ", argv[1]);
perror(NULL);
return -1;
}
int attr = openat(file, argv[2], O_RDONLY|O_XATTR);
if(attr == -1) {
fprintf(stderr, "Cannot open attribute ''%s'': ", argv[2]);
perror(NULL);
return -1;
}
char buf[1024];
ssize_t r = 0;
while((r = read(attr, buf, 1024)) > 0) {
write(STDOUT_FILENO, buf, r);
}
return 0;
}