diff --git a/include/qpdf/QUtil.hh b/include/qpdf/QUtil.hh index 45dc9c5..d0626a2 100644 --- a/include/qpdf/QUtil.hh +++ b/include/qpdf/QUtil.hh @@ -52,6 +52,10 @@ namespace QUtil void binary_stdout(); QPDF_DLL void binary_stdin(); + // Set stdout to line buffered + QPDF_DLL + void setLineBuf(FILE*); + // May modify argv0 QPDF_DLL diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc index bc81ce5..1bdae0f 100644 --- a/libqpdf/QUtil.cc +++ b/libqpdf/QUtil.cc @@ -127,6 +127,14 @@ QUtil::binary_stdin() #endif } +void +QUtil::setLineBuf(FILE* f) +{ +#ifndef _WIN32 + setvbuf(f, (char *) NULL, _IOLBF, 0); +#endif +} + char* QUtil::getWhoami(char* argv0) { diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc index f9af860..431f6da 100644 --- a/qpdf/qpdf.cc +++ b/qpdf/qpdf.cc @@ -534,7 +534,7 @@ parse_encrypt_options( int main(int argc, char* argv[]) { whoami = QUtil::getWhoami(argv[0]); - setvbuf(stdout, (char *) NULL, _IOLBF, 0); + QUtil::setLineBuf(stdout); // For libtool's sake.... if (strncmp(whoami, "lt-", 3) == 0) diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index 68866b5..f499891 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -320,7 +320,7 @@ void runtest(int n, char const* filename) int main(int argc, char* argv[]) { - setvbuf(stdout, (char *) NULL, _IOLBF, 0); + QUtil::setLineBuf(stdout); if ((whoami = strrchr(argv[0], '/')) == NULL) { whoami = argv[0];