Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20260402131633.GN1827@brightrain.aerifal.cx>
Date: Thu, 2 Apr 2026 09:16:33 -0400
From: Rich Felker <dalias@...c.org>
To: Bruno Haible <bruno@...sp.org>
Cc: Collin Funk <collin.funk1@...il.com>, musl@...ts.openwall.com
Subject: Re: standard output is always line buffered for the first line

On Thu, Apr 02, 2026 at 02:47:05PM +0200, Bruno Haible wrote:
> Rich Felker wrote:
> > This code is behaving exactly as it was intended to.
> 
> What was the motivation behind this intent?
> What's the practical advantage of outputting one line, before
> switching to fully-buffered mode?

The motivation is not poking across different layers of abstraction.

The function that sets up the buffers for write mode, __towrite, is
really the only place a probe-in-advance for whether the output device
is a tty could be done without high cost in code duplication (across
different stdio output functions) and performance cost (since putc
would have to do it too, which is of course prohibitive).

But as written, __towrite and pretty much all of the stdio code is
written to an abstraction level of just the buffering structures; the
backend logic specific to writing to file descriptors is all in
__stdio_write (for ones opened at runtime) and __stdout_write (with
the tty detection logic for stdout).

So to do what you'd want, either __towrite would have to poke through
the abstraction and probe for a tty itself, or there'd need to be some
new backend setup/init funciton added.

Of course you could also just do a non-lazy probe at startup, but that
imposes it even on programs not using stdio, which is something we
generally avoid.

So in short, "check at time of first flush, which might be a flush
caused by conservatively assuming we might need a flush when a '\n' is
seen" was the approach that fit best with goals of not making programs
pay for things they don't use and keeping clear boundaries between
abstraction layers.

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.