diff options
author | Daniel Friesel <derf@finalrewind.org> | 2017-10-03 19:58:27 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2017-10-03 19:58:27 +0200 |
commit | de36c62308fb982f9794db87a856fa6aae042ce6 (patch) | |
tree | 54969d668b47aa15602511f5d3b5a2fd7fb9dc8c /src/utils.c | |
parent | 4342eab3c36ed87085fedf87bd0641889051c388 (diff) |
Make shell_escape available as a generic utility function
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c index dfae909..ec30d4a 100644 --- a/src/utils.c +++ b/src/utils.c @@ -201,3 +201,26 @@ char *ereadfile(char *path) return estrdup(buffer); } + +char *shell_escape(char *input) +{ + static char ret[1024]; + unsigned int out = 0, in = 0; + + ret[out++] = '\''; + for (in = 0; input[in] && (out < (sizeof(ret) - 7)); in++) { + if (input[in] == '\'') { + ret[out++] = '\''; + ret[out++] = '"'; + ret[out++] = '\''; + ret[out++] = '"'; + ret[out++] = '\''; + } + else + ret[out++] = input[in]; + } + ret[out++] = '\''; + ret[out++] = '\0'; + + return ret; +} |