nnn

mirror of https://github.com/jarun/nnn
Log | Files | Refs | README | LICENSE

commit 6a79a8285b6cc2866cfcf1c5814efa85af840b96
parent a2720a61a9d6eff455fd9101f0475cba7f7e45bf
Author: xjdeng <micro6947@gmail.com>
Date:   Wed, 26 Nov 2025 10:51:45 +0800

Add return value check of unlink

Diffstat:
Msrc/nnn.c | 24+++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/nnn.c b/src/nnn.c @@ -2094,7 +2094,10 @@ static int editselection(void) /* Save the last modification time */ if (stat(g_tmpfpath, &sb)) { DPRINTF_S(strerror(errno)); - unlink(g_tmpfpath); + if (unlink(g_tmpfpath)) { + DPRINTF_S(strerror(errno)); + printwarn(NULL); + } return -1; } mtime = sb.st_mtime; @@ -2104,7 +2107,10 @@ static int editselection(void) fd = open(g_tmpfpath, O_RDONLY); if (fd == -1) { DPRINTF_S(strerror(errno)); - unlink(g_tmpfpath); + if (unlink(g_tmpfpath)) { + DPRINTF_S(strerror(errno)); + printwarn(NULL); + } return -1; } @@ -2112,13 +2118,20 @@ static int editselection(void) if (mtime == sb.st_mtime) { DPRINTF_S("selection is not modified"); - unlink(g_tmpfpath); + if (unlink(g_tmpfpath)) { + DPRINTF_S(strerror(errno)); + printwarn(NULL); + goto emptyedit; + } return 1; } if (sb.st_size > selbufpos) { DPRINTF_S("edited buffer larger than previous"); - unlink(g_tmpfpath); + if (unlink(g_tmpfpath)) { + DPRINTF_S(strerror(errno)); + printwarn(NULL); + } goto emptyedit; } @@ -2220,7 +2233,8 @@ static void export_file_list(void) spawn(editor, g_tmpfpath, NULL, NULL, F_CLI); if (xconfirm(get_input(messages[MSG_RM_TMP]))) - unlink(g_tmpfpath); + if (unlink(g_tmpfpath)) + DPRINTF_S(strerror(errno)); } static bool init_fcolors(void)