diff options
author | Jeremy Evans <code@jeremyevans.net> | 2020-03-27 10:29:00 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2020-03-27 11:31:19 -0700 |
commit | e1e4ea8fa91a0c62dea69977d989d0bb2b526b64 (patch) | |
tree | a30591188b94f22af43601017267ac9f00a676a4 /io.c | |
parent | 3486a460ea3e450982a6aee7456e5128c7aa1f0e (diff) | |
download | ruby-e1e4ea8fa91a0c62dea69977d989d0bb2b526b64.tar.gz |
Set external encoding correctly for File.open('f', FILE::BINARY) on Windows
Previously, the external encoding was only set correctly for
File::BINARY if keyword arguments were provided. This copies
the logic for the keyword arguments case to the no keyword
arguments case. Possibly it should be refactored into a
separate function.
Fixes [Bug #16737]
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -5955,6 +5955,18 @@ rb_io_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash, #endif SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2(enc2, ecflags); ecopts = Qnil; + if (fmode & FMODE_BINMODE) { +#ifdef O_BINARY + oflags |= O_BINARY; +#endif + if (!has_enc) + rb_io_ext_int_to_encs(rb_ascii8bit_encoding(), NULL, &enc, &enc2, fmode); + } +#if DEFAULT_TEXTMODE + else if (NIL_P(vmode)) { + fmode |= DEFAULT_TEXTMODE; + } +#endif } else { VALUE v; |