1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <stdio.h>
18 #include <string.h>
19 #include <unistd.h>
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <dirent.h>
23 #include <fcntl.h>
24
25
26
27
28
29
30
31 int main(
int argc,
char **argv) {
32 if(argc <
2) {
33 fprintf(stderr,
"Usage: %s <file>", argv[
0]);
34 return -
1;
35 }
36
37 int file = open(argv[
1],
O_RDONLY);
38 if(file == -
1) {
39 fprintf(stderr,
"Cannot open file ''%s'': ", argv[
1]);
40 perror(
NULL);
41 return -
1;
42 }
43
44 int attrdir = openat(file,
".",
O_RDONLY|
O_XATTR);
45 DIR *dir = fdopendir(attrdir);
46 if(!dir) {
47 perror(
"fdopendir");
48 return -
1;
49 }
50
51 struct dirent *ent;
52 while((ent = readdir(dir)) !=
NULL) {
53 if(!strcmp(ent->d_name,
".") || !strcmp(ent->d_name,
"..")) {
54 continue;
55 }
56 printf(
"%s\n", ent->d_name);
57 }
58
59 return 0;
60 }
61
62