Mercurial > octave
diff src/mkoctfile.in.cc @ 29006:139df373c107 stable
Use wide character overload to open file streams on Windows.
* liboctave/system/lo-sysdep.cc, liboctave/system/lo-sysdep.h (fstream,
ifstream, ofstream): Add "wrapper" functions to open file streams.
* libinterp/corefcn/__fcn__.cc (F__ftp_mput__, F__ftp_mget__),
libinterp/corefcn/debug.cc (do_dbtype),
libinterp/corefcn/help.cc (help_system::raw_help_from_docstrings_file),
libinterp/corefcn/load-save.cc (check_gzip_magic,
load_save_system::get_file_format, load_save_system::dump_octave_core,
load_save_system::load, load_save_system::save),
libinterp/corefcn/oct-hist.cc (mk_tmp_hist_file,
history_system::do_edit_history),
libinterp/corefcn/urlwrite.cc (Furlwrite),
libinterp/octave-value/ov-java.cc (read_java_opts, read_classpath_txt),
libinterp/parse-tree/oct-parse.yy (get_file_line),
liboctave/util/cmd-hist.cc (gnu_history::do_append),
liboctave/util/file-info.cc (file_info::snarf_file),
liboctave/util/url-transfer.cc (base_url_transfer::mget_directory,
base_url_transfer::mput_directory): Use new functions.
* libinterp/corefcn/dlmread.cc (dlmread): Use wide character overload for
std::ifstream::open on Windows.
* src/mkoctfile.in.cc (octave_u8_conv_to_encoding): Dummy function for
cross-compiler.
(main): Use wide character overload of std::ofstream::open on Windows.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Fri, 12 Jun 2020 22:13:04 +0200 |
parents | d7169f012ee1 |
children | 040aa7a82662 0a5b15007766 |
line wrap: on
line diff
--- a/src/mkoctfile.in.cc Thu Oct 29 13:45:37 2020 +0100 +++ b/src/mkoctfile.in.cc Fri Jun 12 22:13:04 2020 +0200 @@ -61,6 +61,7 @@ # endif #else # include "mkostemps-wrapper.h" +# include "uniconv-wrappers.h" # include "unistd-wrappers.h" # include "wait-wrappers.h" #endif @@ -89,6 +90,14 @@ return mkostemps (tmpl, suffixlen, 0); } +static char * +octave_u8_conv_to_encoding (const char *tocode, const uint8_t *src, + size_t srclen, size_t *lengthp) +{ + // FIXME: Do we need to provide the conversion here? + return nullptr; +} + static int octave_unlink_wrapper (const char *nm) { @@ -919,8 +928,33 @@ + vars["CPPFLAGS"] + ' ' + vars["ALL_CFLAGS"] + ' ' + incflags + ' ' + defs + ' ' + quote_path (f)); + // FIXME: Use wide character API for popen on Windows. FILE *fd = popen (cmd.c_str (), "r"); + +#if defined (OCTAVE_USE_WINDOWS_API) + // FIXME: liboctinterp isn't linked in to mkoctfile. + // So we cannot use octave::sys::ofstream. Instead we fall back + // on using the functions available from libwrappers. + size_t srclen = dfile.length (); + const uint8_t *src = reinterpret_cast<const uint8_t *> + (dfile.c_str ()); + + size_t length = 0; + wchar_t *wchar = reinterpret_cast<wchar_t *> + (octave_u8_conv_to_encoding ("wchar_t", src, srclen, + &length)); + + std::ofstream fo; + if (wchar != nullptr) + { + fo.open (wchar); + free (static_cast<void *> (wchar)); + } + else + fo.open (dfile.c_str ()); +#else std::ofstream fo (dfile.c_str ()); +#endif size_t pos; while (! feof (fd)) { @@ -953,8 +987,33 @@ + vars["CPPFLAGS"] + ' ' + vars["ALL_CXXFLAGS"] + ' ' + incflags + ' ' + defs + ' ' + quote_path (f)); + // FIXME: Use wide character API for popen on Windows. FILE *fd = popen (cmd.c_str (), "r"); + +#if defined (OCTAVE_USE_WINDOWS_API) + // FIXME: liboctinterp isn't linked in to mkoctfile. + // So we cannot use octave::sys::ofstream. Instead we fall back + // on using the functions available from libwrappers. + size_t srclen = dfile.length (); + const uint8_t *src = reinterpret_cast<const uint8_t *> + (dfile.c_str ()); + + size_t length = 0; + wchar_t *wchar = reinterpret_cast<wchar_t *> + (octave_u8_conv_to_encoding ("wchar_t", src, srclen, + &length)); + + std::ofstream fo; + if (wchar != nullptr) + { + fo.open (wchar); + free (static_cast<void *> (wchar)); + } + else + fo.open (dfile.c_str ()); +#else std::ofstream fo (dfile.c_str ()); +#endif size_t pos; while (! feof (fd)) {