aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-08-20 20:20:06 -0500
committerRob Landley <rob@landley.net>2016-08-20 20:20:06 -0500
commit04f0f34832e6892e9cb212b232891bfa15b7ec0c (patch)
treee01bba6812a0179657d9ea175799594d4ffa30dd
parent3d64b0cc95c5957e53474c3e50f143c61a057104 (diff)
downloadandroid_external_toybox-04f0f34832e6892e9cb212b232891bfa15b7ec0c.tar.gz
android_external_toybox-04f0f34832e6892e9cb212b232891bfa15b7ec0c.tar.bz2
android_external_toybox-04f0f34832e6892e9cb212b232891bfa15b7ec0c.zip
Clean up setfattr.
-rw-r--r--toys/pending/setfattr.c31
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);
}