diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/stringop.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/common/stringop.c b/common/stringop.c index 81d9b963..186fe121 100644 --- a/common/stringop.c +++ b/common/stringop.c | |||
@@ -273,6 +273,32 @@ char *join_args(char **argv, int argc) { | |||
273 | return res; | 273 | return res; |
274 | } | 274 | } |
275 | 275 | ||
276 | static bool has_whitespace(const char *str) { | ||
277 | while (*str) { | ||
278 | if (isspace(*str)) { | ||
279 | return true; | ||
280 | } | ||
281 | ++str; | ||
282 | } | ||
283 | return false; | ||
284 | } | ||
285 | |||
286 | /** | ||
287 | * Add quotes around any argv with whitespaces. | ||
288 | */ | ||
289 | void add_quotes(char **argv, int argc) { | ||
290 | int i; | ||
291 | for (i = 0; i < argc; ++i) { | ||
292 | if (has_whitespace(argv[i])) { | ||
293 | int len = strlen(argv[i]) + 3; | ||
294 | char *tmp = argv[i]; | ||
295 | argv[i] = malloc(len * sizeof(char)); | ||
296 | snprintf(argv[i], len, "\"%s\"", tmp); | ||
297 | free(tmp); | ||
298 | } | ||
299 | } | ||
300 | } | ||
301 | |||
276 | /* | 302 | /* |
277 | * Join a list of strings, adding separator in between. Separator can be NULL. | 303 | * Join a list of strings, adding separator in between. Separator can be NULL. |
278 | */ | 304 | */ |