diff options
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/utils.c b/src/utils.c index 4c06a48..eb128a2 100644 --- a/src/utils.c +++ b/src/utils.c @@ -146,18 +146,21 @@ char *estrjoin(const char *separator, ...) char path_is_url(char *path) { if ((!strncmp(path, "http://", 7)) || (!strncmp(path, "https://", 8)) + || (!strncmp(path, "gopher://", 9)) + || (!strncmp(path, "gophers://", 10)) || (!strncmp(path, "ftp://", 6)) || (!strncmp(path, "file://", 7))) return 1; return 0; } +/* Note: path must end with a trailing / or be an empty string */ /* free the result please */ char *feh_unique_filename(char *path, char *basename) { char *tmpname; char num[10]; - char cppid[10]; + char cppid[12]; static long int i = 1; struct stat st; pid_t ppid; @@ -201,3 +204,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; +} |