Mercurial > octave
changeset 28472:a40e3c3e17fa
maint: merge stable to default.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Sun, 14 Jun 2020 12:17:10 +0200 |
parents | 4d7232bcf6c1 (current diff) a6c89130cfaa (diff) |
children | 04ee5e8694cb |
files | liboctave/system/lo-sysdep.cc |
diffstat | 2 files changed, 62 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/system/file-ops.cc Sat Jun 13 20:12:50 2020 -0700 +++ b/liboctave/system/file-ops.cc Sun Jun 14 12:17:10 2020 +0200 @@ -32,15 +32,18 @@ #include <cstdlib> #include <cstring> -#if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) -# include <algorithm> -#endif +#include <vector> + #if defined (OCTAVE_USE_WINDOWS_API) # include <windows.h> # include <shlwapi.h> #endif -#include <vector> +#if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) +# include <algorithm> +# include "localcharset-wrapper.h" +# include "uniconv-wrappers.h" +#endif #include "areadlink-wrapper.h" #include "canonicalize-file-name-wrapper.h" @@ -699,6 +702,45 @@ std::string retval; +#if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) + // On Windows, convert to locale charset before passing to + // canonicalize_file_name, and convert back to UTF-8 after that. + + // FIXME: This only allows non-ASCII characters in the file or path that + // can be encoded in the locale charset. + // Consider replacing this with std::filesystem::canonical once we allow + // using C++17. + + const char *locale = octave_locale_charset_wrapper (); + const uint8_t *name_u8 = reinterpret_cast<const uint8_t *> + (name.c_str ()); + size_t length = 0; + char *name_locale = octave_u8_conv_to_encoding (locale, name_u8, + name.length () + 1, + &length); + + if (name_locale) + { + char *tmp_locale = + octave_canonicalize_file_name_wrapper (name_locale); + free (name_locale); + + if (tmp_locale) + { + char *tmp = reinterpret_cast<char *> + (octave_u8_conv_from_encoding (locale, tmp_locale, + strlen (tmp_locale), + &length)); + free (tmp_locale); + + if (tmp) + { + retval = std::string (tmp, length); + free (tmp); + } + } + } +#else char *tmp = octave_canonicalize_file_name_wrapper (name.c_str ()); if (tmp) @@ -706,6 +748,7 @@ retval = tmp; free (tmp); } +#endif #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) // Canonical Windows file separator is backslash.
--- a/liboctave/system/lo-sysdep.cc Sat Jun 13 20:12:50 2020 -0700 +++ b/liboctave/system/lo-sysdep.cc Sun Jun 14 12:17:10 2020 +0200 @@ -54,6 +54,20 @@ { std::string retval; +#if defined (OCTAVE_USE_WINDOWS_API) + wchar_t *tmp = _wgetcwd (nullptr, 0); + + if (! tmp) + (*current_liboctave_error_handler) ("unable to find current directory"); + + std::wstring tmp_wstr (tmp); + free (tmp); + + std::string tmp_str = u8_from_wstring (tmp_wstr); + + retval = tmp_str; + +#else // Using octave_getcwd_wrapper ensures that we have a getcwd that // will allocate a buffer as large as necessary if buf and size are // both 0. @@ -65,6 +79,7 @@ retval = tmp; free (tmp); +#endif return retval; }