diff options
| author | Thomas Weißschuh <thomas@t-8ch.de> | 2023-06-13 08:27:48 +0200 |
|---|---|---|
| committer | Thomas Weißschuh <thomas@t-8ch.de> | 2023-06-13 08:27:48 +0200 |
| commit | 88ad4e74628fe0a2fb9403a5f1b70d201ecb3e53 (patch) | |
| tree | 78bc25fcb60cdebcf668eac033cd9c48a34cf443 /libmount/src | |
| parent | 565eebbc455f151216d3dc2d7d795d1654b08e6d (diff) | |
| download | util-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.c | 30 |
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 } }; |
