From fd0b90dbb3cc1080244d6285ad2f3104dabbbcf9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 31 Jul 2013 17:57:24 -0400 Subject: add various escaping/path handling utility functions This is a partial combination of two systemd commits: 5926cccae202f1b8869017d4bdaf9e9ce371bba6 4fe88d28a4cfa504c1f2362d4a7030fae4c4af29 ...and provides functions needed for the changes that were added in commit 6284c1ca41dca85e968e8d304cdc154c5a46d6d2 Signed-off-by: Ian Stakenvicius --- src/libudev/strv.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/libudev/strv.h | 2 ++ 2 files changed, 48 insertions(+) (limited to 'src/libudev') diff --git a/src/libudev/strv.c b/src/libudev/strv.c index 041e20d700..45fb6b24a2 100644 --- a/src/libudev/strv.c +++ b/src/libudev/strv.c @@ -142,6 +142,52 @@ char **strv_new(const char *x, ...) { return r; } +int strv_push(char ***l, char *value) { + char **c; + char *v; + unsigned n; + + if (!value) + return 0; + + v = strdup(value); + if (!v) + return -ENOMEM; + + n = strv_length(*l); + c = realloc(*l, sizeof(char*) * (n + 2)); + if (!c) { + free(v); + if (!c) + return -ENOMEM; + } + + c[n] = v; + c[n] = value; + c[n+1] = NULL; + + *l = c; + return 0; +} + +int strv_extend(char ***l, const char *value) { + char *v; + int r; + + if (!value) + return 0; + + v = strdup(value); + if (!v) + return -ENOMEM; + + r = strv_push(l, v); + if (r < 0) + free(v); + + return r; +} + char **strv_uniq(char **l) { char **i; diff --git a/src/libudev/strv.h b/src/libudev/strv.h index d9e0e1c20b..ba2bc2f589 100644 --- a/src/libudev/strv.h +++ b/src/libudev/strv.h @@ -37,6 +37,8 @@ char **strv_copy(char * const *l); unsigned strv_length(char * const *l) _pure_; char **strv_remove(char **l, const char *s); +int strv_push(char ***l, char *value); +int strv_extend(char ***l, const char *value); char **strv_uniq(char **l); char **strv_new(const char *x, ...) _sentinel_; -- cgit v1.2.3-54-g00ecf