diff options
author | Arun Prakash Jana <engineerarun@gmail.com> | 2019-04-27 20:05:57 +0530 |
---|---|---|
committer | Arun Prakash Jana <engineerarun@gmail.com> | 2019-05-22 08:44:19 +0530 |
commit | b41560572c89344835615d3ac1ba043b72d3fa4d (patch) | |
tree | 8d7991228c2c244df1171273f3ab73d1d6072df6 | |
parent | 8166e0169a797695dcf0ef37c0924c65ef523bf5 (diff) | |
download | nnn-b41560572c89344835615d3ac1ba043b72d3fa4d.tar.gz |
Unify tmp file creation
-rw-r--r-- | src/nnn.c | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -731,6 +731,12 @@ static char *xbasename(char *path) return base ? base + 1 : path; } +static int create_tmp_file() +{ + xstrlcpy(g_tmpfpath + g_tmpfplen - 1, messages[STR_TMPFILE], TMP_LEN_MAX - g_tmpfplen); + return mkstemp(g_tmpfpath); +} + /* Writes buflen char(s) from buf to a file */ static void writecp(const char *buf, const size_t buflen) { @@ -792,9 +798,7 @@ static void showcplist(void) if (!copybufpos) return; - xstrlcpy(g_tmpfpath + g_tmpfplen - 1, messages[STR_TMPFILE], TMP_LEN_MAX - g_tmpfplen); - - fd = mkstemp(g_tmpfpath); + fd = create_tmp_file(); if (fd == -1) { DPRINTF_S("mkstemp failed!"); return; @@ -2312,9 +2316,7 @@ static bool show_stats(const char *fpath, const char *fname, const struct stat * size_t r; FILE *fp; - xstrlcpy(g_tmpfpath + g_tmpfplen - 1, messages[STR_TMPFILE], TMP_LEN_MAX - g_tmpfplen); - - fd = mkstemp(g_tmpfpath); + fd = create_tmp_file(); if (fd == -1) return FALSE; @@ -2567,9 +2569,7 @@ static bool show_help(const char *path) "cc SSHFS mount u Unmount\n" "b^P Prompt ^N Note = Launcher\n"}; - xstrlcpy(g_tmpfpath + g_tmpfplen - 1, messages[STR_TMPFILE], TMP_LEN_MAX - g_tmpfplen); - - fd = mkstemp(g_tmpfpath); + fd = create_tmp_file(); if (fd == -1) return FALSE; |