1 /* setfattr.c - Write POSIX extended attributes.
3 * Copyright 2016 Android Open Source Project.
7 USE_SETFATTR(NEWTOY(setfattr, "hn:|v:x:|[!xv]", TOYFLAG_USR|TOYFLAG_BIN))
13 usage: setfattr [-h] [-x|-n NAME] [-v VALUE] FILE...
15 Write POSIX extended attributes.
17 -h Do not dereference symlink.
18 -n Set given attribute.
19 -x Remove given attribute.
20 -v Set value for attribute -n (default is empty).
30 static void do_setfattr(char *file)
32 int h = toys.optflags & FLAG_h;
34 if (toys.optflags&FLAG_x) {
35 if ((h ? lremovexattr : removexattr)(file, TT.x))
36 perror_msg("removexattr failed");
38 if ((h ? lsetxattr : setxattr)(file, TT.n, TT.v, TT.v?strlen(TT.v):0, 0))
39 perror_msg("setxattr failed");
42 void setfattr_main(void)
46 for (s=toys.optargs; *s; s++) do_setfattr(*s);