summaryrefslogtreecommitdiff
path: root/ratox.c
diff options
context:
space:
mode:
authorsin <sin@2f30.org>2014-09-18 15:03:01 +0100
committersin <sin@2f30.org>2014-09-18 15:19:27 +0100
commit39ae6e0d52714ba468dccfcc1315f63bd4341e87 (patch)
treeeb096f6a1a16bb093fc070103966a2abae28d6c4 /ratox.c
parent935c63ef7e949bbffcce5a66c3bc627e450d1f18 (diff)
Remember to ftruncate() before updating the files
Diffstat (limited to 'ratox.c')
-rw-r--r--ratox.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/ratox.c b/ratox.c
index e8ddac0..4139fed 100644
--- a/ratox.c
+++ b/ratox.c
@@ -217,6 +217,7 @@ cbconnstatus(Tox *m, int32_t fid, uint8_t status, void *udata)
TAILQ_FOREACH(f, &friendhead, entry) {
if (f->fid == fid) {
+ ftruncate(f->fd[FONLINE], 0);
dprintf(f->fd[FONLINE], status == 0 ? "0\n" : "1\n");
return;
}
@@ -301,6 +302,7 @@ cbnamechange(Tox *m, int32_t fid, const uint8_t *data, uint16_t len, void *user)
TAILQ_FOREACH(f, &friendhead, entry) {
if (f->fid == fid) {
+ ftruncate(f->fd[FNAME], 0);
dprintf(f->fd[FNAME], "%s\n", name);
if (memcmp(f->namestr, name, len + 1) == 0)
break;
@@ -324,6 +326,7 @@ cbstatusmessage(Tox *m, int32_t fid, const uint8_t *data, uint16_t len, void *ud
TAILQ_FOREACH(f, &friendhead, entry) {
if (f->fid == fid) {
+ ftruncate(f->fd[FSTATUS], 0);
dprintf(f->fd[FSTATUS], "%s\n", status);
printout("%s changed status: %s\n",
f->namestr[0] == '\0' ? "Anonymous" : f->namestr, status);
@@ -741,13 +744,16 @@ friendcreate(int32_t fid)
}
chdir("..");
+ ftruncate(f->fd[FNAME], 0);
dprintf(f->fd[FNAME], "%s\n", f->namestr);
+ ftruncate(f->fd[FONLINE], 0);
dprintf(f->fd[FONLINE], "%s\n",
tox_get_friend_connection_status(tox, fid) == 0 ? "0" : "1");
r = tox_get_status_message_size(tox, fid);
if (r > sizeof(status) - 1)
r = sizeof(status) - 1;
status[r] = '\0';
+ ftruncate(f->fd[FSTATUS], 0);
dprintf(f->fd[FSTATUS], "%s\n", status);
TAILQ_INSERT_TAIL(&friendhead, f, entry);