Mercurial > octave
changeset 29537:93a751f468d9
Windows: Allow non-ASCII characters in Octave home directory.
* src/shared-fcns.h (w32_get_octave_home): Use Unicode Windows API to get
Octave home directory.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Sat, 17 Apr 2021 09:16:41 +0200 |
parents | 205033e01792 |
children | d1cb1b0e9c05 |
files | src/shared-fcns.h |
diffstat | 1 files changed, 16 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/shared-fcns.h Thu Apr 15 23:16:15 2021 +0200 +++ b/src/shared-fcns.h Sat Apr 17 09:16:41 2021 +0200 @@ -34,13 +34,15 @@ #if defined (OCTAVE_USE_WINDOWS_API) -#include <windows.h> -#include <tlhelp32.h> +# include <windows.h> +# include <tlhelp32.h> +# include <locale> +# include <codecvt> -#if defined (_MSC_VER) -# define popen _popen -# define pclose _pclose -#endif +# if defined (_MSC_VER) +# define popen _popen +# define pclose _pclose +# endif static std::string w32_get_octave_home (void) @@ -49,12 +51,16 @@ std::string bin_dir; - char namebuf[MAX_PATH+1]; - if (GetModuleFileName (GetModuleHandle (nullptr), namebuf, MAX_PATH)) + wchar_t namebuf[MAX_PATH+1]; + DWORD n_size + = GetModuleFileNameW (GetModuleHandle (nullptr), namebuf, MAX_PATH); + if (n_size < MAX_PATH) { - namebuf[MAX_PATH] = '\0'; + // convert wide character string to multibyte UTF-8 string + std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> wchar_conv; + std::string exe_name + = wchar_conv.to_bytes (std::wstring (namebuf, n_size)); - std::string exe_name = namebuf; size_t pos = exe_name.rfind ('\\'); if (pos != std::string::npos)