# HG changeset patch # User Markus Mützel # Date 1572022803 -7200 # Node ID 118606de93598b7d58ad10368da1942c76b72ca7 # Parent 087a21522aa3c063ef87e9496569aeabfe2dfa9b Use the mfile_encoding as default encoding for fopen (bug #55826). * file-io.cc (Ffopen): By default, use the mfile_encoding as encoding for reading and writing files. diff -r 087a21522aa3 -r 118606de9359 libinterp/corefcn/file-io.cc --- a/libinterp/corefcn/file-io.cc Sat Feb 08 09:38:16 2020 +0100 +++ b/libinterp/corefcn/file-io.cc Fri Oct 25 19:00:03 2019 +0200 @@ -56,6 +56,7 @@ #include "iconv-wrappers.h" #include "lo-ieee.h" #include "lo-sysdep.h" +#include "localcharset-wrapper.h" #include "mkostemp-wrapper.h" #include "oct-env.h" #include "oct-locbuf.h" @@ -498,8 +499,9 @@ corresponding system error message. The @var{mode} is a one or two character string that specifies whether the file is to be opened for reading, writing, or both. The @var{encoding} is a character string with a -valid code page identifier. This code page is used when strings are read from -or written to the file. +valid encoding identifier. This encoding is used when strings are read from +or written to the file. By default, the same encoding is used like for reading +.m files. The second form of the @code{fopen} function returns a vector of file ids corresponding to all the currently open files, excluding the @@ -620,7 +622,11 @@ octave_value arch = (nargin > 2) ? args(2) : octave_value ("native"); - octave_value encoding = (nargin > 3) ? args(3) : octave_value ("utf-8"); + octave::input_system& input_sys = interp.get_input_system (); + octave_value encoding = (nargin > 3) ? args(3) + : octave_value (input_sys.mfile_encoding ()); + if (encoding.string_value () == "system") + encoding = octave_value (octave_locale_charset_wrapper ()); int fid = -1;