From: Thomas Weißschuh Date: Tue, 13 Jun 2023 06:27:48 +0000 (+0200) Subject: libmount: (tests) add helper for option list splitting X-Git-Tag: v2.40-rc1~391 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=88ad4e74628fe0a2fb9403a5f1b70d201ecb3e53;p=thirdparty%2Futil-linux.git libmount: (tests) add helper for option list splitting Signed-off-by: Thomas Weißschuh --- 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, " linux|user set to the list" }, { "--get-str", test_get_str, " [linux|user] all options in string" }, { "--get-flg", test_get_flg, " linux|user all options by flags" }, + { "--split", test_split, " split options into key-value pairs"}, { NULL } };