NO

Author Topic: fseek not seeking  (Read 6158 times)

Mikehg

  • Guest
fseek not seeking
« on: November 06, 2004, 11:38:23 PM »
Hi Pelle,

Yeah, me again :)

Using fseek to offset from the current position seems to be giving some strange results?
Code: [Select]

int cnt;
WORD ChunkID;
FILE* FP1;
 FP1=fopen(FileName,"rb");
GET(FP1,&ChunkID,sizeof(WORD));
cnt =ftell(FP1);  // cnt = 2 Here
fseek(FP1,10,SEEK_CUR );
cnt =ftell(FP1); // cnt = 0x20A Here
fclose(FP1);


It seems like something weird is going on with the highorder bits of the offset number?

Thanks,
Mike H.

Mikehg

  • Guest
fseek not seeking
« Reply #1 on: November 06, 2004, 11:42:20 PM »
btw, GET is a BCX macro:

#define GET(A,B,C)fread(B,1,C,A)

Also, ths person that wrote the original program stated that the problem started after 2.9 beta 5 if that is any help?

Mike H.

JohnF

  • Guest
fseek not seeking
« Reply #2 on: November 07, 2004, 08:45:16 AM »
Quote from: "Mikehg"
btw, GET is a BCX macro:

#define GET(A,B,C)fread(B,1,C,A)

Also, ths person that wrote the original program stated that the problem started after 2.9 beta 5 if that is any help?

Mike H.


I just ran your code here with no problem.

Code: [Select]

#define GET(A,B,C)fread(B,1,C,A)
int main(void)
{
char FileName[] = "main.c";
int cnt;
WORD ChunkID;
FILE * FP1;
FP1 = fopen(FileName,"rb");
    GET(FP1,&ChunkID,sizeof(WORD));
cnt = ftell(FP1);   // cnt = 2 Here
printf("%d\n", cnt);
fseek(FP1,10,SEEK_CUR );
cnt = ftell(FP1); // cnt = 12 Here
printf("%d\n", cnt);
fclose(FP1);
return 0;
}


John

Mikehg

  • Guest
fseek not seeking
« Reply #3 on: November 07, 2004, 09:05:43 AM »
Hi John,

Are you using the latest version ?

Are you linking with the MS runtime?, it will work correctly.

Using the PellesC runtime I still 2 and 522

Thanks,
Mike H.

JohnF

  • Guest
fseek not seeking
« Reply #4 on: November 07, 2004, 09:10:52 AM »
Quote from: "Mikehg"
Hi John,

Are you using the latest version ?

Are you linking with the MS runtime?, it will work correctly.

Using the PellesC runtime I still 2 and 522

Thanks,
Mike H.


Sorry, yes I was linking with the MS runtime, and with crt.lib your code does produce the problem.

John

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
fseek not seeking
« Reply #5 on: November 07, 2004, 03:31:50 PM »
It's the previous addition of supporting fflush() on input streams that is causing the problem. fflush() is also used internally by several C runtime functions, causing problems with fseek() in this case. I have no solution at the moment...

Pelle
/Pelle