diff options
| author | Furkan Sahin <furkan-dev@proton.me> | 2019-11-20 22:10:03 -0500 |
|---|---|---|
| committer | Furkan Sahin <furkan-dev@proton.me> | 2019-11-20 22:10:03 -0500 |
| commit | 061773337aa0bf2ac17609b96fbcfa00f59e3efc (patch) | |
| tree | 4942dfcbd3eeea04092ff1b40791b8c25e1f4403 /common | |
| parent | b720e6279a58f15264f453b3c76b798a0a56028d (diff) | |
input_cmd_xkb_file: allow shell path expansion
This allows for shell path expansion for input_cmd_xkb_file. The logic
has been extracted from output_cmd_background
Diffstat (limited to 'common')
| -rw-r--r-- | common/stringop.c | 19 |
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; +} |
