From 4efbbdd8076dcadf0df8ff46a89434d79a3314be Mon Sep 17 00:00:00 2001 From: kcwu Date: Mon, 27 Mar 2006 13:08:55 +0000 Subject: write brc to temporary file and rename it after write successfully. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3310 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/brc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'mbbsd') diff --git a/mbbsd/brc.c b/mbbsd/brc.c index 68f4fdeb..d32e989b 100644 --- a/mbbsd/brc.c +++ b/mbbsd/brc.c @@ -316,14 +316,21 @@ read_brc_buf(void) void brc_finalize(){ char brcfile[STRLEN]; + char tmpfile[STRLEN]; int fd; + int ok=0; brc_update(); setuserfile(brcfile, fn_brc); + setuserfile(tmpfile, fn_brc); + strlcat(tmpfile, ".tmp", sizeof(tmpfile)); if (brc_buf != NULL && - (fd = open(brcfile, O_WRONLY | O_CREAT | O_TRUNC, 0644)) != -1) { - write(fd, brc_buf, brc_size); + (fd = open(tmpfile, O_WRONLY | O_CREAT | O_TRUNC, 0644)) != -1) { + if(write(fd, brc_buf, brc_size)==brc_size) + ok=1; close(fd); } + if(ok) + Rename(tmpfile, brcfile); } int -- cgit v1.2.3