diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-12-21 23:12:05 +0100 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-12-21 23:12:05 +0100 |
commit | b9ec274bed571db9c705b65bb8c0bb6409c34fc4 (patch) | |
tree | c5c4a8f5e5dd906772916fea1084659dc725d5f9 /src/common/utils.c | |
parent | 209ea0657b7970b4b8069ce44b43eecb97681892 (diff) | |
download | blogc-b9ec274bed571db9c705b65bb8c0bb6409c34fc4.tar.gz blogc-b9ec274bed571db9c705b65bb8c0bb6409c34fc4.tar.bz2 blogc-b9ec274bed571db9c705b65bb8c0bb6409c34fc4.zip |
git-receiver: moved shell quote function to common
Diffstat (limited to 'src/common/utils.c')
-rw-r--r-- | src/common/utils.c | 24 |
1 files changed, 24 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); +} |