From 2638802ccd0d0776ebf1867181d4e3950a147074 Mon Sep 17 00:00:00 2001 From: gramanas Date: Sat, 10 Nov 2018 22:47:03 +0200 Subject: Home dir --- src/ckutil.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/ckutil.c') 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; -- cgit v1.2.3