summaryrefslogtreecommitdiff
path: root/src/shared/strv.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-03-04 09:20:51 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-03-04 10:04:50 -0500
commit6e18964d3a365567954fe10ddcfad74babdc427c (patch)
treea1e62c233e0cac0224623049e6fb98b8e450d0ac /src/shared/strv.c
parente062dec5ae1a443d47885537af85d328c83c67db (diff)
Introduce strv_consume which takes ownership
This mirrors set_consume and makes the common use a bit nicer.
Diffstat (limited to 'src/shared/strv.c')
-rw-r--r--src/shared/strv.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/shared/strv.c b/src/shared/strv.c
index 13deba7be7..67706dc381 100644
--- a/src/shared/strv.c
+++ b/src/shared/strv.c
@@ -378,9 +378,18 @@ int strv_push(char ***l, char *value) {
return 0;
}
+int strv_consume(char ***l, char *value) {
+ int r;
+
+ r = strv_push(l, value);
+ if (r < 0)
+ free(value);
+
+ return r;
+}
+
int strv_extend(char ***l, const char *value) {
char *v;
- int r;
if (!value)
return 0;
@@ -389,11 +398,7 @@ int strv_extend(char ***l, const char *value) {
if (!v)
return -ENOMEM;
- r = strv_push(l, v);
- if (r < 0)
- free(v);
-
- return r;
+ return strv_consume(l, v);
}
char **strv_uniq(char **l) {