toybox/toys/other/setfattr.c
<<
>>
Prefs
   1/* setfattr.c - Write POSIX extended attributes.
   2 *
   3 * Copyright 2016 Android Open Source Project.
   4 *
   5 * No standard
   6
   7USE_SETFATTR(NEWTOY(setfattr, "hn:|v:x:|[!xv]", TOYFLAG_USR|TOYFLAG_BIN))
   8
   9config SETFATTR
  10  bool "setfattr"
  11  default y
  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
  26GLOBALS(
  27  char *x, *v, *n;
  28)
  29
  30void setfattr_main(void)
  31{
  32  int h = toys.optflags & FLAG_h, rc;
  33  char **s;
  34
  35  for (s=toys.optargs; *s; s++) {
  36    if (TT.x) rc = (h?lremovexattr:removexattr)(*s, TT.x);
  37    else rc = (h?lsetxattr:setxattr)(*s, TT.n, TT.v, TT.v?strlen(TT.v):0, 0);
  38
  39    if (rc) perror_msg("%s", *s);
  40  }
  41}
  42