On Sun, Mar 03, 2024 at 12:34:16AM +0100, Elie Le Vaillant wrote:
> +static void
> +tac(FILE *fp)
> +{
> +     struct linebuf buf = EMPTY_LINEBUF;
> +     struct line line;
> +     getlines(fp, &buf);
> +
> +     if (buf.nolf) {
> +             /* If the last line is not LF-terminated, the
> +              * first output line should not be either */
> +              buf.nolf--;
> +              buf.lines[buf.nlines - 1].len--;
> +     }
> +
> +     while (buf.nlines--) {
> +             line = buf.lines[buf.nlines];
> +             fwrite(line.data, 1, line.len, stdout);
> +             free(line.data);
> +     }
> +     free(buf.lines);
> +}

I'm not sure what level of optimization the maintainers expect, but
personally, I think there should be separate implementations for
seekable vs non-seekable files to avoid buffering the entire contents of
the file in memory unnecessarily.

Eric

Reply via email to