src/nnn.c | 13 ++++++++----- diff --git a/src/nnn.c b/src/nnn.c index fa61f3763e2b810780d3c9cd61f40141c356d3e5..5284e9ef60ea06f25ce10c17448c9cf887ebbc35 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -1330,7 +1330,7 @@ } } #endif -static void convert_tilde(const char *path, char *buf) +static bool convert_tilde(const char *path, char *buf) { if (tilde_is_home(path)) { ssize_t len = xstrlen(home); @@ -1338,7 +1338,9 @@ ssize_t loclen = xstrlen(path); xstrsncpy(buf, home, len + 1); xstrsncpy(buf + len, path + 1, loclen); + return true; } + return false; } static int create_tmp_file(void) @@ -2762,13 +2764,14 @@ } static void write_lastdir(const char *curpath, const char *outfile) { + bool tilde = false; if (!outfile) xstrsncpy(cfgpath + xstrlen(cfgpath), "/.lastd", 8); else - convert_tilde(outfile, g_buf); + tilde = convert_tilde(outfile, g_buf); int fd = open(outfile - ? (tilde_is_home(outfile) ? g_buf : outfile) + ? (tilde ? g_buf : outfile) : cfgpath, O_CREAT | O_WRONLY | O_TRUNC, S_IWUSR | S_IRUSR); if (fd != -1) { @@ -3836,8 +3839,8 @@ if (id == NNN_PLUG) return pluginstr + kvarr[r].off; val = bmstr + kvarr[r].off; - convert_tilde(val, g_buf); - return abspath((tilde_is_home(val) ? g_buf : val), NULL, buf); + bool tilde = convert_tilde(val, g_buf); + return abspath((tilde ? g_buf : val), NULL, buf); } }