aboutsummaryrefslogtreecommitdiffstats
path: root/libmount/src
diff options
context:
space:
mode:
authorThomas Weißschuh <thomas@t-8ch.de>2023-06-13 08:27:48 +0200
committerThomas Weißschuh <thomas@t-8ch.de>2023-06-13 08:27:48 +0200
commit88ad4e74628fe0a2fb9403a5f1b70d201ecb3e53 (patch)
tree78bc25fcb60cdebcf668eac033cd9c48a34cf443 /libmount/src
parent565eebbc455f151216d3dc2d7d795d1654b08e6d (diff)
downloadutil-linux-88ad4e74628fe0a2fb9403a5f1b70d201ecb3e53.tar.gz
libmount: (tests) add helper for option list splitting
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
Diffstat (limited to 'libmount/src')
-rw-r--r--libmount/src/optlist.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/libmount/src/optlist.c b/libmount/src/optlist.c
index 1e962ec6d8..e93810b47f 100644
--- a/libmount/src/optlist.c
+++ b/libmount/src/optlist.c
@@ -1386,6 +1386,35 @@ static int test_get_flg(struct libmnt_test *ts, int argc, char *argv[])
return rc;
}
+static int test_split(struct libmnt_test *ts, int argc, char *argv[])
+{
+ struct libmnt_optlist *ol;
+ int rc;
+ struct libmnt_iter itr;
+ struct libmnt_opt *opt;
+ const char *name, *value;
+
+ if (argc != 2)
+ return -EINVAL;
+ rc = mk_optlist(&ol, argv[1]);
+ if (rc)
+ goto done;
+
+ mnt_reset_iter(&itr, MNT_ITER_FORWARD);
+
+ while (mnt_optlist_next_opt(ol, &itr, &opt) == 0) {
+ name = mnt_opt_get_name(opt);
+ value = mnt_opt_get_value(opt);
+
+ printf("%s = %s\n", name, value ?: "(null)");
+ }
+
+done:
+ mnt_unref_optlist(ol);
+ return rc;
+}
+
+
int main(int argc, char *argv[])
{
struct libmnt_test tss[] = {
@@ -1396,6 +1425,7 @@ int main(int argc, char *argv[])
{ "--set-flg", test_set_flg, "<list> <flg> linux|user set to the list" },
{ "--get-str", test_get_str, "<list> [linux|user] all options in string" },
{ "--get-flg", test_get_flg, "<list> linux|user all options by flags" },
+ { "--split", test_split, "<list> split options into key-value pairs"},
{ NULL }
};