setfattr.c 851 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* setfattr.c - Write POSIX extended attributes.
  2. *
  3. * Copyright 2016 Android Open Source Project.
  4. *
  5. * No standard
  6. USE_SETFATTR(NEWTOY(setfattr, "hn:|v:x:|[!xv]", TOYFLAG_USR|TOYFLAG_BIN))
  7. config SETFATTR
  8. bool "setfattr"
  9. default y
  10. help
  11. usage: setfattr [-h] [-x|-n NAME] [-v VALUE] FILE...
  12. Write POSIX extended attributes.
  13. -h Do not dereference symlink
  14. -n Set given attribute
  15. -x Remove given attribute
  16. -v Set value for attribute -n (default is empty)
  17. */
  18. #define FOR_setfattr
  19. #include "toys.h"
  20. GLOBALS(
  21. char *x, *v, *n;
  22. )
  23. void setfattr_main(void)
  24. {
  25. int h = toys.optflags & FLAG_h, rc;
  26. char **s;
  27. for (s=toys.optargs; *s; s++) {
  28. if (TT.x) rc = (h?lremovexattr:removexattr)(*s, TT.x);
  29. else rc = (h?lsetxattr:setxattr)(*s, TT.n, TT.v, TT.v?strlen(TT.v):0, 0);
  30. if (rc) perror_msg("%s", *s);
  31. }
  32. }