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 <Friedemann.Kleint@digia.com>
Reviewed-by: Robert Loehning <robert.loehning@digia.com>
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
Kai Koehne 2014-07-15 15:14:52 +02:00
parent 9de7b4d750
commit bb0263eb80
1 changed files with 9 additions and 0 deletions

View File

@ -52,6 +52,10 @@
#include <qcommandlineoption.h>
#include <qcommandlineparser.h>
#ifdef Q_OS_WIN
# include <fcntl.h>
# include <io.h>
#endif // Q_OS_WIN
QT_BEGIN_NAMESPACE
@ -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.
out.open(stdout, mode);
} else {