>From 8a1e4631fc2dddf5ca63039b4a77ae0d33d3cb90 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 16 Jul 2016 14:17:25 +0300 Subject: [PATCH] Open temporary files in binary mode on MS-Windows * libguile/filesys.c (scm_mkstemp) [__MINGW32__]: Make sure the temporary file is open in binary mode. --- libguile/filesys.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libguile/filesys.c b/libguile/filesys.c index 48232e8..c47c2f4 100644 --- a/libguile/filesys.c +++ b/libguile/filesys.c @@ -1472,6 +1472,14 @@ SCM_DEFINE (scm_mkstemp, "mkstemp!", 1, 0, 0, SCM_SYSCALL (rv = mkstemp (c_tmpl)); if (rv == -1) SCM_SYSERROR; +#ifdef __MINGW32__ + /* Files created by this function are used for *.go files, so make + sure they use binary I/O, or else the produced *.go files will be + corrupted by end-of-line conversion and ^Z "software EOF" + misfeature. Gnulib's 'mkstemp' uses the default text mode to + open the file . */ + _setmode (rv, _O_BINARY); +#endif scm_substring_move_x (scm_from_locale_string (c_tmpl), SCM_INUM0, scm_string_length (tmpl), -- 2.9.0.windows.1