From 6eefeb04b900be29d96a87dcdc3938151d98d9bf Mon Sep 17 00:00:00 2001 From: Loo Rong Jie Date: Tue, 7 Aug 2018 04:12:29 -0700 Subject: [singlejar] Set binary flag for Windows /cc @laszlocsomor Closes #5779. PiperOrigin-RevId: 207693540 --- src/tools/singlejar/output_jar.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/tools') diff --git a/src/tools/singlejar/output_jar.cc b/src/tools/singlejar/output_jar.cc index 75be4ca1c7..5b6d24fc6b 100644 --- a/src/tools/singlejar/output_jar.cc +++ b/src/tools/singlejar/output_jar.cc @@ -259,8 +259,15 @@ bool OutputJar::Open() { if (file_) { diag_errx(1, "%s:%d: Cannot open output archive twice", __FILE__, __LINE__); } + // Set execute bits since we may produce an executable output file. - int fd = open(path(), O_CREAT|O_WRONLY|O_TRUNC, 0777); + int mode = O_CREAT | O_WRONLY | O_TRUNC; +#ifdef _WIN32 + // Make sure output file is in binary mode, or \r\n will be converted to \n. + mode |= _O_BINARY; +#endif + + int fd = open(path(), mode, 0777); if (fd < 0) { diag_warn("%s:%d: %s", __FILE__, __LINE__, path()); return false; -- cgit v1.2.3