diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2015-06-23 10:57:41 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2015-08-07 15:50:43 +0000 |
commit | 04c14b25412cdbde834e8369bd7268cbe92873c0 (patch) | |
tree | ee8eb7a5b1c72665dd81a5aadda654863a413345 /src/basic | |
parent | 61ee6939819963b7845c101485e188ca2a8119c6 (diff) |
strv: Add strv_shell_escape
This modifies the strv in-place, replacing strings with their escaped
version. It's mostly just a convenience function for when you need to
join a strv together because it's passed as a string to something, and
the separator needs escaping.
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/strv.c | 20 | ||||
-rw-r--r-- | src/basic/strv.h | 1 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/basic/strv.c b/src/basic/strv.c index 79a9d8d421..eaf440a4b2 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -694,6 +694,26 @@ char **strv_reverse(char **l) { return l; } +char **strv_shell_escape(char **l, const char *bad) { + char **s; + + /* Escapes every character in every string in l that is in bad, + * edits in-place, does not roll-back on error. */ + + STRV_FOREACH(s, l) { + char *v; + + v = shell_escape(*s, bad); + if (!v) + return NULL; + + free(*s); + *s = v; + } + + return l; +} + bool strv_fnmatch(char* const* patterns, const char *s, int flags) { char* const* p; diff --git a/src/basic/strv.h b/src/basic/strv.h index 954da06fcb..f07da8cdf3 100644 --- a/src/basic/strv.h +++ b/src/basic/strv.h @@ -145,6 +145,7 @@ void strv_print(char **l); })) char **strv_reverse(char **l); +char **strv_shell_escape(char **l, const char *bad); bool strv_fnmatch(char* const* patterns, const char *s, int flags); |