aboutsummaryrefslogtreecommitdiff
path: root/toys/pending
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-02-20 15:57:30 -0800
committerRob Landley <rob@landley.net>2019-02-21 12:12:01 -0600
commit4cc20c7554685df53228c4cf6d551b07837f8bf1 (patch)
tree947c469dbf22a74c594c8f480e5e984a19943f4f /toys/pending
parent01503a37c9ae3bc608e7ba9fb476ab7aca3fdd46 (diff)
downloadtoybox-4cc20c7554685df53228c4cf6d551b07837f8bf1.tar.gz
getfattr: add --only-values.
Needed to improve cp(1) testing.
Diffstat (limited to 'toys/pending')
-rw-r--r--toys/pending/getfattr.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/toys/pending/getfattr.c b/toys/pending/getfattr.c
index c58994d6..bf2c04c8 100644
--- a/toys/pending/getfattr.c
+++ b/toys/pending/getfattr.c
@@ -4,7 +4,7 @@
*
* No standard
-USE_GETFATTR(NEWTOY(getfattr, "dhn:", TOYFLAG_USR|TOYFLAG_BIN))
+USE_GETFATTR(NEWTOY(getfattr, "(only-values)dhn:", TOYFLAG_USR|TOYFLAG_BIN))
config GETFATTR
bool "getfattr"
@@ -17,6 +17,7 @@ config GETFATTR
-d Show values as well as names
-h Do not dereference symbolic links
-n Show only attributes with the given name
+ --only-values Don't show names
*/
#define FOR_getfattr
@@ -36,7 +37,7 @@ static void do_getfattr(char *file)
char *keys, *key;
int i, key_count;
- if (toys.optflags&FLAG_h) {
+ if (FLAG(h)) {
getter = lgetxattr;
lister = llistxattr;
}
@@ -59,14 +60,14 @@ static void do_getfattr(char *file)
sorted_keys[i++] = key;
qsort(sorted_keys, key_count, sizeof(char *), qstrcmp);
- printf("# file: %s\n", file);
+ if (!FLAG(only_values)) printf("# file: %s\n", file);
for (i = 0; i < key_count; i++) {
key = sorted_keys[i];
if (TT.n && strcmp(TT.n, key)) continue;
- if (toys.optflags&FLAG_d) {
+ if (FLAG(d) || FLAG(only_values)) {
ssize_t value_len;
char *value = NULL;
@@ -77,13 +78,15 @@ static void do_getfattr(char *file)
free(value);
}
- if (!value) puts(key);
+ if (FLAG(only_values)) {
+ if (value) printf("%s", value);
+ } else if (!value) puts(key);
else printf("%s=\"%s\"\n", key, value);
free(value);
} else puts(key); // Just list names.
}
- xputc('\n');
+ if (!FLAG(only_values)) xputc('\n');
free(sorted_keys);
}