pretty-print: introduce WITH_BUFFERED_STDERR macro to enable buffering

Then, the buffer will be flushed and buffering will be disabled on
exiting from the scope.
This commit is contained in:
Yu Watanabe
2024-09-03 09:34:50 +09:00
parent b9e4b2c569
commit 4edbea7de2
3 changed files with 32 additions and 20 deletions
+1 -4
View File
@@ -798,8 +798,7 @@ static int update_render_progress(sd_event_source *source, void *userdata) {
/* We're outputting lots of small strings to STDERR, which is unbuffered by default. So let's turn
* on full buffering, so we pass this all to the TTY in one go, to make things more efficient */
char buffer[LONG_LINE_MAX];
setvbuf(stderr, buffer, _IOFBF, sizeof(buffer));
WITH_BUFFERED_STDERR;
if (!terminal_is_dumb()) {
for (size_t i = 0; i <= n; i++)
@@ -855,8 +854,6 @@ static int update_render_progress(sd_event_source *source, void *userdata) {
} else if (!exiting)
fputs("------\n", stderr);
fflush(stderr);
setvbuf(stderr, NULL, _IONBF, 0); /* Disable buffering again */
return 0;
}