aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-11-20 22:10:03 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-11-21 10:36:15 -0500
commit2f858a1adaef17241ca6fda973f2b867b25e1971 (patch)
tree4942dfcbd3eeea04092ff1b40791b8c25e1f4403 /common
parentinput/keyboard: cleanup xkb_file error handing (diff)
downloadsway-2f858a1adaef17241ca6fda973f2b867b25e1971.tar.gz
sway-2f858a1adaef17241ca6fda973f2b867b25e1971.tar.zst
sway-2f858a1adaef17241ca6fda973f2b867b25e1971.zip
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.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}