Re: [AD] memfile

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Mon, Dec 20, 2010 at 4:40 PM, Peter Wang <novalazy@xxxxxxxxxx> wrote:
> On 2010-12-20, Matthew Leverton <meffer@xxxxxxxxxx> wrote:
>> Is the memfile addon excluded from documentation / installation for
>> any reason? (Or at least, last I checked, it was not there.)
>
> You can if you want.
>
Attached is an implementation of ungetc for memfile and an additional
mode parameter for the al_open_memfile. It also includes
documentation. (Not included is that the memfile.h header file should
be renamed to allegro_memfile.h.)

For fungetc, I used a buffer (hardcoded to 16 bytes). I think it
basically follows the standard ungetc, except that it allows and
reports negative positions. (My man pages for ungetc say that behavior
is undefined... it happens to stop at 0, but allows the following getc
to work as long as there's no intermediate seeking or telling.)

Seeking or writing is relative to the "virtual" position, but
immediately clears the entire ungetc buffer, regardless if the seek or
write actually extends past the ungetc buffer. Trying to write before
position 0 causes it to write at 0. I think this is all the same
behavior as the standard file implementation, with the exception of
some undefined things regarding negative positions.

The mode parameter accepts any combination of "r" and "w". If you open
the file for neither read or write, then you cannot do anything useful
with it. The file always opens at position 0. Trying to read or write
without proper permission just returns 0.

Note that I swapped the order of the first two parameters. All the I/O
functions go buffer, size... so I think it's more consistent if
open_memfile is the same way.

--
Matthew Leverton

Attachment: memfile.diff.gz
Description: GNU Zip compressed data



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/