Home | History | Annotate | Download | only in pending
      1 /* setfattr.c - Write POSIX extended attributes.
      2  *
      3  * Copyright 2016 Android Open Source Project.
      4  *
      5  * No standard
      6 
      7 USE_SETFATTR(NEWTOY(setfattr, "hn:|v:x:|[!xv]", TOYFLAG_USR|TOYFLAG_BIN))
      8 
      9 config SETFATTR
     10   bool "setfattr"
     11   default n
     12   help
     13     usage: setfattr [-h] [-x|-n NAME] [-v VALUE] FILE...
     14 
     15     Write POSIX extended attributes.
     16 
     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).
     21 */
     22 
     23 #define FOR_setfattr
     24 #include "toys.h"
     25 
     26 GLOBALS(
     27   char *x, *v, *n;
     28 )
     29 
     30 static void do_setfattr(char *file)
     31 {
     32   int h = toys.optflags & FLAG_h;
     33 
     34   if (toys.optflags&FLAG_x) {
     35     if ((h ? lremovexattr : removexattr)(file, TT.x))
     36       perror_msg("removexattr failed");
     37   } else
     38     if ((h ? lsetxattr : setxattr)(file, TT.n, TT.v, TT.v?strlen(TT.v):0, 0))
     39       perror_msg("setxattr failed");
     40 }
     41 
     42 void setfattr_main(void)
     43 {
     44   char **s;
     45 
     46   for (s=toys.optargs; *s; s++) do_setfattr(*s);
     47 }
     48