summaryrefslogtreecommitdiff
path: root/src/systemd/src/basic/strv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/systemd/src/basic/strv.c')
-rw-r--r--src/systemd/src/basic/strv.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/systemd/src/basic/strv.c b/src/systemd/src/basic/strv.c
index e885c5981e..4ee2e5cd69 100644
--- a/src/systemd/src/basic/strv.c
+++ b/src/systemd/src/basic/strv.c
@@ -28,9 +28,7 @@
#include "alloc-util.h"
#include "escape.h"
-#if 0 /* NM_IGNORED */
#include "extract-word.h"
-#endif /* NM_IGNORED */
#include "fileio.h"
#include "string-util.h"
#include "strv.h"
@@ -564,6 +562,42 @@ int strv_extend(char ***l, const char *value) {
return strv_consume(l, v);
}
+int strv_extend_front(char ***l, const char *value) {
+ size_t n, m;
+ char *v, **c;
+
+ assert(l);
+
+ /* Like strv_extend(), but prepends rather than appends the new entry */
+
+ if (!value)
+ return 0;
+
+ n = strv_length(*l);
+
+ /* Increase and overflow check. */
+ m = n + 2;
+ if (m < n)
+ return -ENOMEM;
+
+ v = strdup(value);
+ if (!v)
+ return -ENOMEM;
+
+ c = realloc_multiply(*l, sizeof(char*), m);
+ if (!c) {
+ free(v);
+ return -ENOMEM;
+ }
+
+ memmove(c+1, c, n * sizeof(char*));
+ c[0] = v;
+ c[n+1] = NULL;
+
+ *l = c;
+ return 0;
+}
+
char **strv_uniq(char **l) {
char **i;