aboutsummaryrefslogtreecommitdiff
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 @@
#include <stdlib.h>
#include <string.h>
#include <strings.h>
+#include <wordexp.h>
#include "list.h"
#include "log.h"
#include "stringop.h"
@@ -309,3 +310,21 @@ char *argsep(char **stringp, const char *delim, char *matched) {
}
return start;
}
+
+bool expand_path(char **path) {
+ wordexp_t p = {0};
+ while (strstr(*path, " ")) {
+ *path = realloc(*path, strlen(*path) + 2);
+ char *ptr = strstr(*path, " ") + 1;
+ memmove(ptr + 1, ptr, strlen(ptr) + 1);
+ *ptr = '\\';
+ }
+ if (wordexp(*path, &p, 0) != 0 || p.we_wordv[0] == NULL) {
+ wordfree(&p);
+ return false;
+ }
+ free(*path);
+ *path = join_args(p.we_wordv, p.we_wordc);
+ wordfree(&p);
+ return true;
+}