MaikeruDev
Joined: 16 Jul 2007 Posts: 13 Location: Poland
|
Posted: Wed Nov 07, 2007 9:55 am Post subject: fread is not working properly? |
|
|
I noticed that fread function from PS2SDK isn't working properly, when I was trying to read something like that:
sample code:
| Code: |
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: |
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? |
|