From e2135c364a121be1d5fa2f165c0a5c37d35afd3d Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Mon, 30 Apr 2018 21:58:52 +0000 Subject: [PATCH] iniWriteFile(): don't truncate the file to 0-bytes before writing the contents, instead truncate to the new length after writing the contents. This should make .ini files more tolerate of "out of disk space" situations and reduce the risk of lost data (0-byte .ini files) due to low/no disk space. --- src/xpdev/ini_file.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/xpdev/ini_file.c b/src/xpdev/ini_file.c index 54a7bd4120..61864e4adb 100644 --- a/src/xpdev/ini_file.c +++ b/src/xpdev/ini_file.c @@ -2361,11 +2361,10 @@ BOOL DLLCALL iniWriteFile(FILE* fp, const str_list_t list) size_t count; rewind(fp); - - if(chsize(fileno(fp),0)!=0) /* truncate */ - return(FALSE); - count = strListWriteFile(fp,list,"\n"); + fflush(fp); + if(chsize(fileno(fp), ftell(fp))!=0) /* truncate */ + return(FALSE); return(count == strListCount(list)); } -- GitLab