Mail Archives: djgpp/2004/12/20/17:15:39
Apparently the error about retrieving data compatible with
a char* was in error;
the *other* point I was attempting to expose, is "WHAT does
happen when in order to obtain a *specific* type of object,
and there are insufficient bytes, WHAT should be expected
from fread THEN ?
As I tried to illustrate: a long is 4-bytes, double 8-bytes,
if these number of bytes can not be retrieved, due to
truncation, etc of the file, THEN what should be expected?
I hope this clarifies things. Thanks.
It is meant to trigger discussion; not criticize DJGPP.
On Sat, 18 Dec 2004 19:06:44 -0500, DJ Delorie <dj AT delorie DOT com> wrote:
>
>> Apparently we are seeing that using fread() and reading a size that
>> exceeds the end_of_file, causes ZERO elements to be returned; this
>> does not seem to be what most people are expecting:
>
>Please post your test program. Mine works fine:
>
>#include <stdio.h>
>
>char buf[1024];
>
>main()
>{
> int rv;
> FILE *f = fopen("afile.bin", "rb");
>
> rv = fread (buf, sizeof(char), 128, f);
> printf("ask 128 got %d\n", rv);
>
> rv = fread (buf, sizeof(char), 64, f);
> printf("ask 64 got %d\n", rv);
>
> rv = fread (buf, sizeof(char), 128, f);
> printf("ask 128 got %d\n", rv);
>
> fclose(f);
> exit(0);
>}
>
>C:\TMP> dj
>ask 128 got 128
>ask 64 got 64
>ask 128 got 64
>
>C:\TMP>
- Raw text -