diff options
author | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2006-03-27 21:08:55 +0800 |
---|---|---|
committer | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2006-03-27 21:08:55 +0800 |
commit | 4efbbdd8076dcadf0df8ff46a89434d79a3314be (patch) | |
tree | f3e2511b3f8cdf4d1979f16175df165ca9b9c669 /mbbsd | |
parent | f1487a508b7e68c242d092a874d2b4ecd3a1ed6e (diff) | |
download | pttbbs-4efbbdd8076dcadf0df8ff46a89434d79a3314be.tar pttbbs-4efbbdd8076dcadf0df8ff46a89434d79a3314be.tar.gz pttbbs-4efbbdd8076dcadf0df8ff46a89434d79a3314be.tar.bz2 pttbbs-4efbbdd8076dcadf0df8ff46a89434d79a3314be.tar.lz pttbbs-4efbbdd8076dcadf0df8ff46a89434d79a3314be.tar.xz pttbbs-4efbbdd8076dcadf0df8ff46a89434d79a3314be.tar.zst pttbbs-4efbbdd8076dcadf0df8ff46a89434d79a3314be.zip |
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
Diffstat (limited to 'mbbsd')
-rw-r--r-- | mbbsd/brc.c | 11 |
1 files changed, 9 insertions, 2 deletions
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 |