Re: [PATCH v2] Refactor recv_sideband()
- From
Nicolas Pitre <nico@fluxnic.net>
- Date
- Jun 27, 2016, 20:47 UTC
- Message-ID
- <alpine.LFD.2.20.1606271640230.2550@knanqh.ubzr>
- In-Reply-To
- <146705966655.11886.6547584744094511110@typhoon>
On Mon, 27 Jun 2016, Lukas Fleischer wrote:
Show 13 quoted lines
> On Mon, 27 Jun 2016 at 19:50:13, Junio C Hamano wrote: > > Jeff King <peff@peff.net> writes: > > > > > On Mon, Jun 27, 2016 at 08:54:22AM -0700, Junio C Hamano wrote: > > > > > >> It's just you used xwrite() there that introduced a different issue. > > >> Wouldn't replacing it with fwrite(stderr) without changing anything > > >> else solve that? > > I do not see how using fwrite() buys us anything. Neither fwrite() nor > fputs() nor fprintf() guarantee to call write() only once. Each of these > three functions is buffered when printing to stdout and unbuffered when > printing to stderr.
You are right. However, in practice:
- fprintf(stderr, "%s", buffer) is likely to call write() only once given there is only one string specifier, and
- On Windows the ANSI escape sequences are interpreted by fprintf() and not by write() nor by the actual display console code. Insane but such is life sometimes.
So the point is simply to replace your call to write() by a call to fprintf(..., "%*s", ...) in your patch which should provide the same end result as before.
Nicolas