diff options
Diffstat (limited to 'src/ckutil.c')
-rw-r--r-- | src/ckutil.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/ckutil.c b/src/ckutil.c index 5f8da98..0895677 100644 --- a/src/ckutil.c +++ b/src/ckutil.c @@ -143,17 +143,12 @@ int str_is_empty(const char *s) { return 1; } -int swap_tilde_and_home(char *ret, const char *s) { - if (!ret || !s) { - return -1; - } - char *home = getenv("HOME"); - if (!home) { +int swap_tilde_with_home(char *ret, const char *s, const char *home) { + if (!ret || !s || !home) { return -1; } ulong i; ulong homelen = strlen(home); - if (s[0] == '~') { strcpy(ret, home); for (i = 1; i < strlen(s); i++) { @@ -162,6 +157,16 @@ int swap_tilde_and_home(char *ret, const char *s) { return 0; } + return -1; +} + +int swap_home_with_tilde(char *ret, const char *s, const char *home) { + if (!ret || !s || !home) { + return -1; + } + ulong i; + ulong homelen = strlen(home); + for (i = 0; i < strlen(home); i++) { if (s[i] != home[i]) { return -1; |