• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <unistd.h>
2 #include <stdio.h>
3 #include <sys/types.h>
4 #include <errno.h>
5 #include <sys/syscall.h>
6 #include <string.h>
7 #include <sys/xattr.h>
8 
main(int argc,char * argv[])9 int main(int argc, char *argv[])
10 {
11 	ssize_t s;
12 	char *tok;
13 	char value[1024];
14 	char list[1024];
15 	int rc = 0;
16 
17 	if (argc < 2) {
18 		printf("Please enter a file name as argument.\n");
19 		return -1;
20 	}
21 
22 	if (-1 == (s = listxattr(argv[1], list, 1024))) {
23 		perror("listxattr");
24 		return 1;
25 	}
26 	if (s == 0) {
27 		printf("No xattrs defined for %s, further testcase useless\n",
28 		       argv[1]);
29 		return 1;
30 	}
31 	tok = strtok(list, "\0");
32 	s = getxattr(argv[1], tok, (void *)value, 1024);
33 	if (-1 == s) {
34 		perror("getxattr");
35 		return -1;
36 	}
37 
38 	s = lsetxattr(argv[1], tok, (void *)value, s, 0);
39 
40 	if (s == -1) {
41 		printf("User unable to change extended attributes %s !\n",
42 		       argv[1]);
43 		printf("errno = %i\n", errno);
44 		rc = 1;
45 	}
46 
47 	s = lremovexattr(argv[1], tok);
48 	if (s == -1) {
49 		printf("User unable to remove extended attributes %s !\n",
50 		       argv[1]);
51 		printf("errno = %i\n", errno);
52 		rc = 1;
53 	}
54 
55 	return rc;
56 }
57