aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-05-03 11:35:59 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-05-03 11:35:59 +0000
commit8abae8841019fcc75852131b2d1d16bf5710b4b7 (patch)
tree4403426255190fb5cb4dbf82a0c77c81a0469a37
parent96b99b860cc15f13b85b1b2d5b5b20ab7183a652 (diff)
downloadbusybox-w32-8abae8841019fcc75852131b2d1d16bf5710b4b7.tar.gz
busybox-w32-8abae8841019fcc75852131b2d1d16bf5710b4b7.tar.bz2
busybox-w32-8abae8841019fcc75852131b2d1d16bf5710b4b7.zip
vi: do not truncate file to zero length. closes bug 2944.
function old new delta file_write 98 104 +6
-rw-r--r--editors/vi.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/editors/vi.c b/editors/vi.c
index 454cfcee4..4e5a5ac4a 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -2437,11 +2437,16 @@ static int file_write(char * fn, char * first, char * last)
2437 return -2; 2437 return -2;
2438 } 2438 }
2439 charcnt = 0; 2439 charcnt = 0;
2440 fd = open(fn, (O_WRONLY | O_CREAT | O_TRUNC), 0666); 2440 /* By popular request we do not open file with O_TRUNC,
2441 * but instead ftruncate() it _after_ successful write.
2442 * Might reduce amount of data lost on power fail etc.
2443 */
2444 fd = open(fn, (O_WRONLY | O_CREAT), 0666);
2441 if (fd < 0) 2445 if (fd < 0)
2442 return -1; 2446 return -1;
2443 cnt = last - first + 1; 2447 cnt = last - first + 1;
2444 charcnt = full_write(fd, first, cnt); 2448 charcnt = full_write(fd, first, cnt);
2449 ftruncate(fd, charcnt);
2445 if (charcnt == cnt) { 2450 if (charcnt == cnt) {
2446 // good write 2451 // good write
2447 //file_modified = FALSE; // the file has not been modified 2452 //file_modified = FALSE; // the file has not been modified