aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/stringop.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/common/stringop.c b/common/stringop.c
index ac7df296..0df2b33d 100644
--- a/common/stringop.c
+++ b/common/stringop.c
@@ -5,6 +5,7 @@
5#include <stdlib.h> 5#include <stdlib.h>
6#include <string.h> 6#include <string.h>
7#include <strings.h> 7#include <strings.h>
8#include <wordexp.h>
8#include "list.h" 9#include "list.h"
9#include "log.h" 10#include "log.h"
10#include "stringop.h" 11#include "stringop.h"
@@ -309,3 +310,21 @@ char *argsep(char **stringp, const char *delim, char *matched) {
309 } 310 }
310 return start; 311 return start;
311} 312}
313
314bool expand_path(char **path) {
315 wordexp_t p = {0};
316 while (strstr(*path, " ")) {
317 *path = realloc(*path, strlen(*path) + 2);
318 char *ptr = strstr(*path, " ") + 1;
319 memmove(ptr + 1, ptr, strlen(ptr) + 1);
320 *ptr = '\\';
321 }
322 if (wordexp(*path, &p, 0) != 0 || p.we_wordv[0] == NULL) {
323 wordfree(&p);
324 return false;
325 }
326 free(*path);
327 *path = join_args(p.we_wordv, p.we_wordc);
328 wordfree(&p);
329 return true;
330}