loudness-scanner
loudness-scanner copied to clipboard
set stdout/stderr to be unbuffered when they are not connected to a file
This fixes somewhat jumbled output due to mixed usage of stdout and stderr without proper calls to fflush() and letting stdio choose the default buffering strategy. On win32, pipes are often used instead pty (since there's no pty on win32), therefore this issue has higher possibility to appear. For example, running scanner in psuedo terminal application such as mintty is enough to reproduce the issue. unbuffered mode is a simple way to ensure output order to be always preserved, at the expence of tiny I/O overhead that should be negligible.
Sorry, don't merge this patch. It turned out that simply setting unbuffered mode causes problem due to multithreading. Since MSVC doesn't support line buffered mode, we cannot rely on it, too.
Hmm, sorry again. The previous comment seems my mistake (was testing with wrong branch..), it works here.