diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-12-21 09:20:39 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-12-21 09:20:39 +0100 |
commit | 0e125234a3373ed0145d3a624e244f2c2c6f63ac (patch) | |
tree | 5e0e93dab65bf62930b1c454903158b4efeba156 | |
parent | 473656ef01e872a92844a50d01d6a7ede3dcc599 (diff) | |
parent | 3d8a942a56e1de32e23cd02eada3899c4d6d1033 (diff) |
Merge pull request #70389 from bruvzg/unicode_stdio
Fix reading Unicode from stdio.
-rw-r--r-- | drivers/unix/os_unix.cpp | 6 | ||||
-rw-r--r-- | drivers/unix/os_unix.h | 2 | ||||
-rw-r--r-- | platform/windows/os_windows.cpp | 7 |
3 files changed, 7 insertions, 8 deletions
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index b02a100784..711fd7b962 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -152,12 +152,10 @@ Vector<String> OS_Unix::get_video_adapter_driver_info() const { String OS_Unix::get_stdin_string(bool p_block) { if (p_block) { char buff[1024]; - String ret = stdin_buf + fgets(buff, 1024, stdin); - stdin_buf = ""; - return ret; + return String::utf8(fgets(buff, 1024, stdin)); } - return ""; + return String(); } Error OS_Unix::get_entropy(uint8_t *r_buffer, int p_bytes) { diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h index ce06a52a95..68d2dd0042 100644 --- a/drivers/unix/os_unix.h +++ b/drivers/unix/os_unix.h @@ -46,8 +46,6 @@ protected: virtual void finalize_core() override; - String stdin_buf; - public: OS_Unix(); diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index a083a98c72..f8633d29ac 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -1164,8 +1164,11 @@ bool OS_Windows::set_environment(const String &p_var, const String &p_value) con String OS_Windows::get_stdin_string(bool p_block) { if (p_block) { - char buff[1024]; - return fgets(buff, 1024, stdin); + WCHAR buff[1024]; + DWORD count = 0; + if (ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE), buff, 1024, &count, nullptr)) { + return String::utf16((const char16_t *)buff, count); + } } return String(); |