summaryrefslogtreecommitdiff
path: root/src/basic/strv.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-02-01 12:50:18 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-02-02 10:35:30 +0100
commit6e888894fc043a023731129ae4eb8ae5633e9f97 (patch)
tree328295722724757118bbed979e73a230f51fb0f3 /src/basic/strv.c
parent7b1aaf6633cad80c1e59eeedaf60595a3ec1efc5 (diff)
downloadsystemd-6e888894fc043a023731129ae4eb8ae5633e9f97.tar.gz
basic/strv: add function to insert items at position
Diffstat (limited to 'src/basic/strv.c')
-rw-r--r--src/basic/strv.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/basic/strv.c b/src/basic/strv.c
index 1103245a36..68e2e874b4 100644
--- a/src/basic/strv.c
+++ b/src/basic/strv.c
@@ -446,7 +446,7 @@ int strv_push_pair(char ***l, char *a, char *b) {
return 0;
}
-int strv_push_prepend(char ***l, char *value) {
+int strv_insert(char ***l, unsigned position, char *value) {
char **c;
unsigned n, m, i;
@@ -454,6 +454,7 @@ int strv_push_prepend(char ***l, char *value) {
return 0;
n = strv_length(*l);
+ position = MIN(position, n);
/* increase and check for overflow */
m = n + 2;
@@ -464,10 +465,12 @@ int strv_push_prepend(char ***l, char *value) {
if (!c)
return -ENOMEM;
- for (i = 0; i < n; i++)
+ for (i = 0; i < position; i++)
+ c[i] = (*l)[i];
+ c[position] = value;
+ for (i = position; i < n; i++)
c[i+1] = (*l)[i];
- c[0] = value;
c[n+1] = NULL;
free(*l);