From 54dbf0fa510afcd3058a5da66e1c4a390c2ba89b Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 6 Apr 2024 08:58:12 +0100 Subject: time: mitigation for interleaved output When the 'time' applet is run in a pipeline, like so: time seq 1 10 | tail -2 stdout from 'tail' and stderr from 'time' can be interleaved. This is particularly the case with the ConEmu terminal emulator. The interleaving can be reduced, though not eliminated, by buffering the output of 'time'. Adds 40-44 bytes. (GitHub issue #396) --- miscutils/time.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/miscutils/time.c b/miscutils/time.c index e24221341..09a474979 100644 --- a/miscutils/time.c +++ b/miscutils/time.c @@ -471,6 +471,9 @@ int time_main(int argc UNUSED_PARAM, char **argv) /* $TIME has lowest prio (-v,-p,-f FMT override it) */ const char *output_format = getenv("TIME") ? : default_format; char *output_filename; +#if ENABLE_PLATFORM_MINGW32 + char buffer[256]; +#endif int output_fd; int opt; int ex; @@ -524,6 +527,9 @@ int time_main(int argc UNUSED_PARAM, char **argv) /* Cheat. printf's are shorter :) */ xdup2(output_fd, STDOUT_FILENO); +#if ENABLE_PLATFORM_MINGW32 + setvbuf(stdout, buffer, _IOFBF, sizeof(buffer)); +#endif summarize(output_format, argv, &res); ex = WEXITSTATUS(res.waitstatus); -- cgit v1.2.3-55-g6feb