summaryrefslogtreecommitdiff
path: root/src/shared/strv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/strv.c')
-rw-r--r--src/shared/strv.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/shared/strv.c b/src/shared/strv.c
index a5f8a2aff6..fdb658c0a3 100644
--- a/src/shared/strv.c
+++ b/src/shared/strv.c
@@ -388,7 +388,7 @@ int strv_push(char ***l, char *value) {
n = strv_length(*l);
- /* increase and check for overflow */
+ /* Increase and check for overflow */
m = n + 2;
if (m < n)
return -ENOMEM;
@@ -404,6 +404,34 @@ int strv_push(char ***l, char *value) {
return 0;
}
+int strv_push_pair(char ***l, char *a, char *b) {
+ char **c;
+ unsigned n, m;
+
+ if (!a && !b)
+ return 0;
+
+ n = strv_length(*l);
+
+ /* increase and check for overflow */
+ m = n + !!a + !!b + 1;
+ if (m < n)
+ return -ENOMEM;
+
+ c = realloc_multiply(*l, sizeof(char*), m);
+ if (!c)
+ return -ENOMEM;
+
+ if (a)
+ c[n++] = a;
+ if (b)
+ c[n++] = b;
+ c[n] = NULL;
+
+ *l = c;
+ return 0;
+}
+
int strv_push_prepend(char ***l, char *value) {
char **c;
unsigned n, m, i;
@@ -444,6 +472,18 @@ int strv_consume(char ***l, char *value) {
return r;
}
+int strv_consume_pair(char ***l, char *a, char *b) {
+ int r;
+
+ r = strv_push_pair(l, a, b);
+ if (r < 0) {
+ free(a);
+ free(b);
+ }
+
+ return r;
+}
+
int strv_consume_prepend(char ***l, char *value) {
int r;