From 16d1b940fa923ab2f20c7c813754d160685bcb78 Mon Sep 17 00:00:00 2001 From: sin Date: Tue, 7 Oct 2014 01:01:10 +0100 Subject: Reset fd offset when writing out --- ratox.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ratox.c b/ratox.c index 5c80373..f39465d 100644 --- a/ratox.c +++ b/ratox.c @@ -369,6 +369,7 @@ cbcallinvite(void *av, int32_t cnum, void *udata) f->name, avconfig.audio_sample_rate, avconfig.audio_channels); ftruncate(f->fd[FCALL_PENDING], 0); + lseek(f->fd[FCALL_PENDING], 0, SEEK_SET); dprintf(f->fd[FCALL_PENDING], "1\n"); f->av.state = av_CallStarting; @@ -558,6 +559,7 @@ cancelrxcall(struct friend *f, char *action) f->fd[FCALL_OUT] = -1; } ftruncate(f->fd[FCALL_PENDING], 0); + lseek(f->fd[FCALL_PENDING], 0, SEEK_SET); dprintf(f->fd[FCALL_PENDING], "0\n"); } @@ -636,6 +638,7 @@ cbconnstatus(Tox *m, int32_t frnum, uint8_t status, void *udata) TAILQ_FOREACH(f, &friendhead, entry) { if (f->num == frnum) { ftruncate(f->fd[FONLINE], 0); + lseek(f->fd[FONLINE], 0, SEEK_SET); dprintf(f->fd[FONLINE], "%d\n", status); return; } @@ -712,6 +715,7 @@ cbnamechange(Tox *m, int32_t frnum, const uint8_t *data, uint16_t len, void *use if (memcmp(f->name, name, len + 1) == 0) break; ftruncate(f->fd[FNAME], 0); + lseek(f->fd[FNAME], 0, SEEK_SET); dprintf(f->fd[FNAME], "%s\n", name); printout(": %s : Name > %s\n", f->name, name); memcpy(f->name, name, len + 1); @@ -733,6 +737,7 @@ cbstatusmessage(Tox *m, int32_t frnum, const uint8_t *data, uint16_t len, void * TAILQ_FOREACH(f, &friendhead, entry) { if (f->num == frnum) { ftruncate(f->fd[FSTATUS], 0); + lseek(f->fd[FSTATUS], 0, SEEK_SET); dprintf(f->fd[FSTATUS], "%s\n", status); printout(": %s : Status > %s\n", f->name, status); break; @@ -826,6 +831,7 @@ cbfilecontrol(Tox *m, int32_t frnum, uint8_t rec_sen, uint8_t fnum, uint8_t ctrl f->fd[FFILE_OUT] = -1; } ftruncate(f->fd[FFILE_PENDING], 0); + lseek(f->fd[FFILE_PENDING], 0, SEEK_SET); f->rxstate = TRANSFER_NONE; } break; @@ -861,6 +867,7 @@ cbfilesendreq(Tox *m, int32_t frnum, uint8_t fnum, uint64_t fsz, } ftruncate(f->fd[FFILE_PENDING], 0); + lseek(f->fd[FFILE_PENDING], 0, SEEK_SET); dprintf(f->fd[FFILE_PENDING], "%s\n", filename); f->rxstate = TRANSFER_INPROGRESS; printout(": %s : Rx > Pending %s\n", f->name, filename); @@ -923,6 +930,7 @@ cancelrxtransfer(struct friend *f) f->fd[FFILE_OUT] = -1; } ftruncate(f->fd[FFILE_PENDING], 0); + lseek(f->fd[FFILE_PENDING], 0, SEEK_SET); f->rxstate = TRANSFER_NONE; } } @@ -1398,6 +1406,7 @@ setname(void *data) datasave(); printout("Name > %s\n", name); ftruncate(gslots[NAME].fd[OUT], 0); + lseek(gslots[NAME].fd[OUT], 0, SEEK_SET); dprintf(gslots[NAME].fd[OUT], "%s\n", name); } @@ -1418,6 +1427,7 @@ setstatus(void *data) datasave(); printout("Status > %s\n", status); ftruncate(gslots[STATUS].fd[OUT], 0); + lseek(gslots[STATUS].fd[OUT], 0, SEEK_SET); dprintf(gslots[STATUS].fd[OUT], "%s\n", status); } @@ -1451,6 +1461,7 @@ sendfriendreq(void *data) r = tox_add_friend(tox, id, (uint8_t *)buf, strlen(buf)); ftruncate(gslots[REQUEST].fd[ERR], 0); + lseek(gslots[REQUEST].fd[ERR], 0, SEEK_SET); if (r < 0) { dprintf(gslots[REQUEST].fd[ERR], "%s\n", reqerr[-r]); @@ -1488,10 +1499,12 @@ setnospam(void *data) datasave(); printout("Nospam > %08X\n", nsval); ftruncate(gslots[NOSPAM].fd[OUT], 0); + lseek(gslots[NOSPAM].fd[OUT], 0, SEEK_SET); dprintf(gslots[NOSPAM].fd[OUT], "%08X\n", nsval); tox_get_address(tox, address); ftruncate(idfd, 0); + lseek(idfd, 0, SEEK_SET); for (i = 0; i < TOX_FRIEND_ADDRESS_SIZE; i++) dprintf(idfd, "%02X", address[i]); dprintf(idfd, "\n"); -- cgit v1.2.3