diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/utils.c | 24 | ||||
-rw-r--r-- | src/common/utils.h | 5 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/common/utils.c b/src/common/utils.c index f745146..9061e40 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -643,3 +643,27 @@ bc_trie_foreach(bc_trie_t *trie, bc_trie_foreach_func_t func, bc_trie_foreach_node(trie->root, str, func, user_data); bc_string_free(str, true); } + + +char* +bc_shell_quote(const char *command) +{ + bc_string_t *rv = bc_string_new(); + bc_string_append_c(rv, '\''); + if (command != NULL) { + for (size_t i = 0; i < strlen(command); i++) { + switch (command[i]) { + case '!': + bc_string_append(rv, "'\\!'"); + break; + case '\'': + bc_string_append(rv, "'\\''"); + break; + default: + bc_string_append_c(rv, command[i]); + } + } + } + bc_string_append_c(rv, '\''); + return bc_string_free(rv, false); +} diff --git a/src/common/utils.h b/src/common/utils.h index 020f243..2bda45d 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -99,4 +99,9 @@ size_t bc_trie_size(bc_trie_t *trie); void bc_trie_foreach(bc_trie_t *trie, bc_trie_foreach_func_t func, void *user_data); + +// shell + +char* bc_shell_quote(const char *command); + #endif /* _UTILS_H */ |