diff options
-rw-r--r-- | toys/pending/setfattr.c | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/toys/pending/setfattr.c b/toys/pending/setfattr.c index 9f17ce05..080991f2 100644 --- a/toys/pending/setfattr.c +++ b/toys/pending/setfattr.c @@ -4,21 +4,20 @@ * * No standard -USE_SETFATTR(NEWTOY(setfattr, "hn:v:x:[!xv]", TOYFLAG_USR|TOYFLAG_BIN)) +USE_SETFATTR(NEWTOY(setfattr, "hn:|v:x:|[!xv]", TOYFLAG_USR|TOYFLAG_BIN)) config SETFATTR bool "setfattr" default y help - usage: setfattr [-h] -n NAME [-v VALUE] FILE... - usage: setfattr [-h] -x NAME FILE... + usage: setfattr [-h] [-x|-n NAME] [-v VALUE] FILE... Write POSIX extended attributes. - -h Do not dereference symbolic links. - -n Set value of given attribute. - -x Remove value of given attribute. - -v Value to use with -n (default is empty). + -h Do not dereference symlink. + -n Set given attribute. + -x Remove given attribute. + -v Set value for attribute -n (default is empty). */ #define FOR_setfattr @@ -30,27 +29,19 @@ GLOBALS( static void do_setfattr(char *file) { - int (*setter)(const char *, const char *, const void *, size_t, int) = - setxattr; - int (*remover)(const char *, const char *) = removexattr; - - if (toys.optflags&FLAG_h) { - setter = lsetxattr; - remover = lremovexattr; - } + int h = toys.optflags & FLAG_h; if (toys.optflags&FLAG_x) { - if (remover(file, TT.x)) perror_msg("removexattr failed"); - } else { - if (setter(file, TT.n, TT.v, TT.v ? strlen(TT.v) : 0, 0)) + if ((h ? lremovexattr : removexattr)(file, TT.x)) + perror_msg("removexattr failed"); + } else + if ((h ? lsetxattr : setxattr)(file, TT.n, TT.v, TT.v?strlen(TT.v):0, 0)) perror_msg("setxattr failed"); - } } void setfattr_main(void) { char **s; - if (!(toys.optflags&(FLAG_n|FLAG_x))) error_exit("need 'n' or 'x'"); for (s=toys.optargs; *s; s++) do_setfattr(*s); } |