From 78899705d57f4e0f4c8146fdc4136b7b615f19a3 Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 02:20:50 +0800 Subject: [PATCH] Bug of fseek and wrong setting of position. --- modules/src/object/rd.c | 2 +- modules/src/object/wr.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/src/object/rd.c b/modules/src/object/rd.c index 01da90dbc..26c9f224c 100644 --- a/modules/src/object/rd.c +++ b/modules/src/object/rd.c @@ -77,7 +77,7 @@ int rd_fdopen(FILE* fd) for (i = 0; i < NPARTS; i++) outseek[i] = 0; offcnt = 0; - rd_base = fseek(fd, 0L, SEEK_CUR); + rd_base = ftell(fd); if (rd_base < 0) { return 0; } diff --git a/modules/src/object/wr.c b/modules/src/object/wr.c index d5f77e30f..e4f304bca 100644 --- a/modules/src/object/wr.c +++ b/modules/src/object/wr.c @@ -38,7 +38,8 @@ __wr_flush(struct fil *ptr) #ifdef OUTSEEK /* seek to correct position even if we aren't going to write now */ if (currpos != ptr->currpos) { - currpos = fseek(ptr->fd, ptr->currpos, SEEK_SET); + fseek(ptr->fd, ptr->currpos, SEEK_SET); + currpos = ptr->currpos; } #endif if (ptr->pnow > ptr->pbegin) { @@ -129,7 +130,8 @@ static void BEGINSEEK(int p, long o) ptr->fd = outfile; ptr->currpos = o; #else - ptr->currpos = fseek(ptr->fd, o, SEEK_SET); + fseek(ptr->fd, o, SEEK_SET); + ptr->currpos = o; #endif if (p >= PARTRELO) o = 0; /* no attempt to align writes for the time being */ @@ -259,8 +261,11 @@ wr_outsect(int s) if (s != sectionnr && s >= (SECTCNT-1) && sectionnr >= (SECTCNT-1)) { #ifdef OUTSEEK - if (currpos != ptr->currpos) - currpos = fseek(ptr->fd, ptr->currpos, SEEK_SET); + if (currpos != ptr->currpos) + { + fseek(ptr->fd, ptr->currpos, SEEK_SET); + currpos -> ptr->currpos; + } #endif wr_bytes(ptr->fd, ptr->pbegin, (long)(ptr->pnow - ptr->pbegin)); ptr->currpos += ptr->pnow - ptr->pbegin; @@ -269,7 +274,8 @@ wr_outsect(int s) #endif offset[sectionnr] = ptr->currpos; if (offset[s] != ptr->currpos) { - ptr->currpos = fseek(ptr->fd, offset[s], SEEK_SET); + fseek(ptr->fd, offset[s], SEEK_SET); + ptr->currpos = offset[s]; #ifdef OUTSEEK currpos = ptr->currpos; #endif