> I don't see how this can be helped other than keeping buffers allocated
> on a per open-file basis — and that would be overkill.

We run an embdeed os at work for which we stole many ideas from plan9.

It has a lib9pfile like library to make writing servers easier.
Generally it uses an array of initialised C structures to define the
hierarchy you want to serve, which contains functions to generate the
contents of these files; Each file also has an associated read and write
flag word. Files can be read:

        line at a time - the library assembles the lines into the
                requested buffer's worth

        file at a time - contents generated in malloced memory on open
                and freed on close

        raw access - requests passed direct to underlying function

writing files can be flagged smilarly:

        line at a time - newlines and leading and trailing whitespace stripped

        file at a time - application specific function called only on close

        raw - as above.

This has been useful and I have thought about writing a similar library for
plan9 but have not done so yet, its difficult to decide what is useful often
enough to libraryise and what is just "nice to have".

-Steve

Reply via email to