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