OSDN Git Service

Minor cleanup on setfattr.c
authorRob Landley <rob@landley.net>
Wed, 27 Dec 2017 17:21:21 +0000 (11:21 -0600)
committerRob Landley <rob@landley.net>
Wed, 27 Dec 2017 17:21:21 +0000 (11:21 -0600)
toys/pending/setfattr.c

index 7e8bae2..efec9a5 100644 (file)
@@ -27,21 +27,15 @@ 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)
 {
+  int h = toys.optflags & FLAG_h, rc;
   char **s;
 
-  for (s=toys.optargs; *s; s++) do_setfattr(*s);
+  for (s=toys.optargs; *s; s++) {
+    if (TT.x) rc = (h?lremovexattr:removexattr)(*s, TT.x);
+    else rc = (h?lsetxattr:setxattr)(*s, TT.n, TT.v, TT.v?strlen(TT.v):0, 0);
+
+    if (rc) perror_msg("%s", *s);
+  }
 }