Mail Archives: djgpp/1998/04/27/04:17:32
Gerhard W. Gruber wrote:
>
> I'm not sure if this is an error in the standard library or if the
> behaviour in this case is not exactly defined.
>
> I'm trying to read a file into memory. My buffer to read in is 4096 bytes
> long and the file is 10 bytes long.
>
> I seek to position 5 of the file and call read with read(hdl, buffer,
> 4096). The result of read should be the number of bytes actually read or -1
> if an error occured. In this case it should return 5 bytes, because the
> remainder of the file is 5 bytes, but I get -1.
>
> Is this an error or is this behaviour correct?
It is not correct to return -1 unless there is an error situation.
Reading beyond EOF is not considered an error situation. So it seems
that this behaviour is incorrect.
However, are you SURE that nothing else fails.
e.g. can't it be that the open call fails? Do you open the file for
reading? Does the lseek call succeed?
Please post a short program that still shows this erratic behaviour.
--
\ Vik /-_-_-_-_-_-_/
\___/ Heyndrickx /
\ /-_-_-_-_-_-_/ Knight in the Order of the Unsigned Types
- Raw text -