Collin Funk wrote:
> Wouldn't it be a bit easier, and a bit more safe, to buffer things
> ourselves and just use read/write?
>
> By that I mean, change 'struct linebuffer' to be something like this:
>
> struct linebuffer
> {
> char *buffer; /* The current line. */
> idx_t nalloc; /* The number of bytes allocated for
> BUFFER. */
> idx_t eol; /* The index of the delimiter in BUFFER. */
> char iobuf[BUFSIZE]; /* The buffer with read data. */
> idx_t iobuf_used; /* The number of bytes in IOBUF not yet
> copied to BUFFER. */
> };
>
> Then allocate and copy to BUFFER as needed so that we read BUFSIZE bytes
> at a time?
This mean would to duplicate functionality that is built-in in the FILE I/O
APIs.
In other words: If you are given a file descriptor and you want to
heap-allocate a buffer for improved speed, think twice. It's the FILE API,
and there are very good chances that this API provides what you need.
Don't reinvent the wheel.
Bruno