aboutsummaryrefslogtreecommitdiff
path: root/toys/pending
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-10-20 22:29:10 -0500
committerRob Landley <rob@landley.net>2016-10-20 22:29:10 -0500
commit5913da6ea5c15960cef54f2c7f080123330aa72d (patch)
treecce09d6f76c4a42d5f9cc1def21f9145e9931c93 /toys/pending
parent9c0ad3248ff89dc9c9dc9eed193ce6fd378d85fa (diff)
downloadtoybox-5913da6ea5c15960cef54f2c7f080123330aa72d.tar.gz
Close to cutting a release and I don't want to have setfattr in defconfig
without getfattr, so I'm putting it back in pending for now.
Diffstat (limited to 'toys/pending')
-rw-r--r--toys/pending/setfattr.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/toys/pending/setfattr.c b/toys/pending/setfattr.c
new file mode 100644
index 00000000..9a41a4da
--- /dev/null
+++ b/toys/pending/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 n
+ 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);
+}