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.
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user