#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <fcntl.h>
int main(int argc, char **argv) {
if(argc < 2) {
fprintf(stderr, "Usage: %s <file>", 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 attrdir = openat(file, ".", O_RDONLY|O_XATTR);
DIR *dir = fdopendir(attrdir);
if(!dir) {
perror("fdopendir");
return -1;
}
struct dirent *ent;
while((ent = readdir(dir)) != NULL) {
if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) {
continue;
}
printf("%s\n", ent->d_name);
}
return 0;
}