Page 1 of 1

fread is not working properly?

Posted: Wed Nov 07, 2007 9:55 am
by MaikeruDev
I noticed that fread function from PS2SDK isn't working properly, when I was trying to read something like that:
sample code:

Code: Select all

unsigned int int_var;
unsigned short int sint_var;
FILE *some_fd = fopen("some_file_that_have_over_2MB","rb");
fread(&sint_var,1,2,some_fd); // this will be ok
fread(&int_var,1,4,some_fd); // this will be ok
fread(&sint_var,1,2,some_fd); // after this ftell function returns 0xffffffff
But when I changed 3rd fread to following code, it was ok.

Code: Select all

fread(((unsigned char*)&sint_var)+0 ,1,1,some_fd);
fread(((unsigned char*)&sint_var)+1 ,1,1,some_fd);
It's happens also in other places in my code when I'm trying to read 2 bytes at time with fread. With one byte and four I haven't any problems.

Still I can use two fgetc (I saw this uses fread :) ) or just two times fread for one byte, but this is ugly :).

Have anybody similar issues?