aboutsummaryrefslogtreecommitdiff
path: root/toys/other
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-08-20 20:24:30 -0500
committerRob Landley <rob@landley.net>2016-08-20 20:24:30 -0500
commitbfbf1a89be7bf25b836a8a2333207f7065f7935b (patch)
treea7da3c053d38c322619c5a86fc9d36d4222779b5 /toys/other
parent04f0f34832e6892e9cb212b232891bfa15b7ec0c (diff)
downloadtoybox-bfbf1a89be7bf25b836a8a2333207f7065f7935b.tar.gz
Promote setfattr
Diffstat (limited to 'toys/other')
-rw-r--r--toys/other/setfattr.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/toys/other/setfattr.c b/toys/other/setfattr.c
new file mode 100644
index 00000000..080991f2
--- /dev/null
+++ b/toys/other/setfattr.c
@@ -0,0 +1,47 @@
+/* setfattr.c - Write POSIX extended attributes.
+ *
+ * Copyright 2016 Android Open Source Project.
+ *
+ * No standard
+
+USE_SETFATTR(NEWTOY(setfattr, "hn:|v:x:|[!xv]", TOYFLAG_USR|TOYFLAG_BIN))
+
+config SETFATTR
+ bool "setfattr"
+ default y
+ help
+ usage: setfattr [-h] [-x|-n NAME] [-v VALUE] FILE...
+
+ Write POSIX extended attributes.
+
+ -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
+#include "toys.h"
+
+GLOBALS(
+ char *x, *v, *n;
+)
+
+static void do_setfattr(char *file)
+{
+ int h = toys.optflags & FLAG_h;
+
+ if (toys.optflags&FLAG_x) {
+ 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;
+
+ for (s=toys.optargs; *s; s++) do_setfattr(*s);
+}