]> Sergey Matveev's repositories - nnn.git/commitdiff
Unify tmp file creation
authorArun Prakash Jana <engineerarun@gmail.com>
Sat, 27 Apr 2019 14:35:57 +0000 (20:05 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Wed, 22 May 2019 03:14:19 +0000 (08:44 +0530)
src/nnn.c

index 578d79e17e77c06e7a6dfa450c97ce1bb6fdbb93..7b4c7e46b0ece14b40a3f831ccd124fd8f0eb0de 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -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;