summaryrefslogtreecommitdiffstats
path: root/lib/strutils.c
diff options
context:
space:
mode:
authorMilan Broz2012-07-26 15:52:04 +0200
committerKarel Zak2012-07-26 16:26:27 +0200
commitf5077b5180c58dec734d1c1a8d19c8632496a864 (patch)
tree61c20935f6241e59cd255cd6dec59a5b8270c2cd /lib/strutils.c
parentdmesg: improve err handling code (diff)
downloadkernel-qcow2-util-linux-f5077b5180c58dec734d1c1a8d19c8632496a864.tar.gz
kernel-qcow2-util-linux-f5077b5180c58dec734d1c1a8d19c8632496a864.tar.xz
kernel-qcow2-util-linux-f5077b5180c58dec734d1c1a8d19c8632496a864.zip
lib/strutils: add string_add_to_idarray() - parse and add to id list
Signed-off-by: Milan Broz <mbroz@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/strutils.c')
-rw-r--r--lib/strutils.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/strutils.c b/lib/strutils.c
index 036ae0639..5dda13805 100644
--- a/lib/strutils.c
+++ b/lib/strutils.c
@@ -479,6 +479,33 @@ int string_to_idarray(const char *list, int ary[], size_t arysz,
}
/*
+ * Parses the array like string_to_idarray but if format is "+aaa,bbb"
+ * it adds fields to array instead of replacing them.
+ */
+int string_add_to_idarray(const char *list, int ary[], size_t arysz,
+ int *ary_pos, int (name2id)(const char *, size_t))
+{
+ const char *list_add;
+ int r;
+
+ if (!list || !*list || !ary_pos ||
+ *ary_pos < 0 || (size_t) *ary_pos > arysz)
+ return -1;
+
+ if (list[0] == '+')
+ list_add = &list[1];
+ else {
+ list_add = list;
+ *ary_pos = 0;
+ }
+
+ r = string_to_idarray(list_add, &ary[*ary_pos], arysz - *ary_pos, name2id);
+ if (r > 0)
+ *ary_pos += r;
+ return r;
+}
+
+/*
* LIST ::= <item> [, <item>]
*
* The <item> is translated to 'id' by name2id() function and the 'id' is used