[En-Nut-Discussion] fseek beyonf EOF on PHAT
Ole Reinhardt
ole.reinhardt at embedded-it.de
Thu Jul 7 09:27:30 CEST 2011
Hi Harald,
> On 7/4/2011 4:01 PM, Ole Reinhardt wrote:
> > http://pubs.opengroup.org/onlinepubs/009695399/functions/fseek.html
> >
> > says, that fseek should allow setting the file pointer beyond the end of
> > file and should fill up the gap with 0 if write to the file follows.
>
> Yes, this is not implemented. I vaguely remember it is documented
> somewhere. If not, I'm sorry.
>
>
>
> The reason was, that it looked quite complicated to me. I'd appreciate
> it, if you'll try your luck.
My first naive approach would be to allow the file position pointer to
become larger than the filesize. If you do a read on the file and the
pointer is beyond the filesize an error (EOF) would be returned, if we
do a write and the pointer is beyond EOF we can just fill up the file
with 0 up to the current file position.
So one would have to modify just three functions:
seek (to allow seeking beyond EOF)
read (to return EOF, of the position is beyond EOF)
write (to fill up the gap with 0 if the position is beyond EOF)
What do you think?
> In any case, it is a bug not to return an error.
Right. I have to double check this again and also have to check the
behaviour of the e.g. linux implementation of fseek / write / read etc.
I will try to implement it accordingly.
Bye,
Ole
--
Thermotemp GmbH, Embedded-IT
Embedded Hard-/ Software and Open Source Development,
Integration and Consulting
http://www.embedded-it.de
Geschäftsstelle Siegen - Steinstraße 67 - D-57072 Siegen -
tel +49 (0)271 5513597, +49 (0)271-73681 - fax +49 (0)271 736 97
Hauptsitz - Hademarscher Weg 7 - 13503 Berlin
Tel +49 (0)30 4315205 - Fax +49 (0)30 43665002
Geschäftsführer: Jörg Friedrichs, Ole Reinhardt
Handelsregister Berlin Charlottenburg HRB 45978 UstID DE 156329280
More information about the En-Nut-Discussion
mailing list