fread is not working properly?

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
MaikeruDev
Posts: 13
Joined: Mon Jul 16, 2007 3:09 am
Location: Poland
Contact:

fread is not working properly?

Post 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?
Post Reply