Diff between 5f2a5127d6b3ee7c022049af604b9e08ec75bc8b and 36bf0bd0421922c6d730131cb873c7e1fe9fd898

Changed Files

File Additions Deletions Status
tools/obexctl.c +12 -11 modified

Full Patch

diff --git a/tools/obexctl.c b/tools/obexctl.c
index 512a145..b4fdc1c 100644
--- a/tools/obexctl.c
+++ b/tools/obexctl.c
@@ -33,6 +33,7 @@
 #include <signal.h>
 #include <sys/signalfd.h>
 #include <inttypes.h>
+#include <wordexp.h>
 
 #include <readline/readline.h>
 #include <readline/history.h>
@@ -2030,8 +2031,9 @@ static char **cmd_completion(const char *text, int start, int end)
 
 static void rl_handler(char *input)
 {
+	wordexp_t w;
 	int argc;
-	char **argv = NULL;
+	char **argv;
 	int i;
 
 	if (!input) {
@@ -2045,18 +2047,16 @@ static void rl_handler(char *input)
 	if (!strlen(input))
 		goto done;
 
-	g_strstrip(input);
 	add_history(input);
 
-	argv = g_strsplit(input, " ", -1);
-	if (argv == NULL)
+	if (wordexp(input, &w, WRDE_NOCMD))
 		goto done;
 
-	for (argc = 0; argv[argc];)
-		argc++;
+	if (w.we_wordc == 0)
+		goto free_we;
 
-	if (argc == 0)
-		goto done;
+	argv = w.we_wordv;
+	argc = w.we_wordc;
 
 	for (i = 0; cmd_table[i].cmd; i++) {
 		if (strcmp(argv[0], cmd_table[i].cmd))
@@ -2064,13 +2064,13 @@ static void rl_handler(char *input)
 
 		if (cmd_table[i].func) {
 			cmd_table[i].func(argc, argv);
-			goto done;
+			goto free_we;
 		}
 	}
 
 	if (strcmp(argv[0], "help")) {
 		printf("Invalid command\n");
-		goto done;
+		goto free_we;
 	}
 
 	printf("Available commands:\n");
@@ -2083,8 +2083,9 @@ static void rl_handler(char *input)
 					cmd_table[i].desc ? : "");
 	}
 
+free_we:
+	wordfree(&w);
 done:
-	g_strfreev(argv);
 	free(input);
 }