path: root/src/tools
diff options
authorKai Koehne <>2014-07-15 15:14:52 +0200
committerKai Koehne <>2014-07-16 10:57:10 +0200
commitbb0263eb80620b64057b6a0a1d6bccad3d3e6282 (patch)
treef70a279f4195300b626eaa5960322a90529c1d1b /src/tools
parent9de7b4d7501c7e8e9eb561d02149a52b05a2bc1d (diff)
rcc: Prevent CRLF conversion on Windows for -binary
Fix an issue on Windows where rcc -binary project.qrc >project.rcc resulted in a corrupted file (\n was automatically replaced with \r\n). This is caused by Qt using fwrite internally, which will automatically replace linefeed with carriage-return for streams opened in text mode. The fix forces stdout to binary mode in this case. Task-number: QTBUG-39422 Change-Id: Ib5b5e82db922dc389d160b0115dbafe8641c95fd Reviewed-by: Friedemann Kleint <> Reviewed-by: Robert Loehning <> Reviewed-by: Joerg Bornemann <> Reviewed-by: hjk <>
Diffstat (limited to 'src/tools')
1 files changed, 9 insertions, 0 deletions
diff --git a/src/tools/rcc/main.cpp b/src/tools/rcc/main.cpp
index 5ded9a9b78..0dcbcafb11 100644
--- a/src/tools/rcc/main.cpp
+++ b/src/tools/rcc/main.cpp
@@ -52,6 +52,10 @@
#include <qcommandlineoption.h>
#include <qcommandlineparser.h>
+#ifdef Q_OS_WIN
+# include <fcntl.h>
+# include <io.h>
+#endif // Q_OS_WIN
@@ -252,6 +256,11 @@ int runRcc(int argc, char *argv[])
if (outFilename.isEmpty() || outFilename == QLatin1String("-")) {
+#ifdef Q_OS_WIN
+ // Make sure fwrite to stdout doesn't do LF->CRLF
+ if (library.format() == RCCResourceLibrary::Binary)
+ _setmode(_fileno(stdout), _O_BINARY);
+#endif // Q_OS_WIN
// using this overload close() only flushes., mode);
} else {