commit afeefcb703161b392e7a0b327db4e13a0bff85ad
parent a2720a61a9d6eff455fd9101f0475cba7f7e45bf
Author: Arun Prakash Jana <engineerarun@gmail.com>
Date: Mon, 1 Dec 2025 19:30:43 +0530
Merge pull request #2096 from MicroMilo/master
Add return value check of unlink
Diffstat:
1 file changed, 22 insertions(+), 6 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;
}
@@ -2219,8 +2232,11 @@ 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 (xconfirm(get_input(messages[MSG_RM_TMP]))) {
+ if (unlink(g_tmpfpath)) {
+ DPRINTF_S(strerror(errno));
+ }
+ }
}
static bool init_fcolors(void)