From 4bb48a4a5c881e26b2d3d9d6fc9b2e7fc444c133 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 5 Aug 2023 20:33:48 +0200 Subject: [PATCH] Ported from godot4: Fix reading Unicode from stdio. - bruvzg https://github.com/godotengine/godot/commit/3d8a942a56e1de32e23cd02eada3899c4d6d1033 --- drivers/unix/os_unix.cpp | 4 +--- drivers/unix/os_unix.h | 2 -- platform/windows/os_windows.cpp | 7 +++++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 6183451df..4d846468a 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -138,9 +138,7 @@ void OS_Unix::alert(const String &p_alert, const String &p_title) { String OS_Unix::get_stdin_string() { char buff[1024]; - String ret = stdin_buf + fgets(buff, 1024, stdin); - stdin_buf = ""; - return ret; + return String::utf8(fgets(buff, 1024, stdin)); } String OS_Unix::get_name() const { diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h index 97bde6824..e40c10c5c 100644 --- a/drivers/unix/os_unix.h +++ b/drivers/unix/os_unix.h @@ -46,8 +46,6 @@ protected: virtual void finalize_core(); - String stdin_buf; - public: OS_Unix(); diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 670ae9305..3d38571a2 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -3166,8 +3166,11 @@ bool OS_Windows::set_environment(const String &p_var, const String &p_value) con } String OS_Windows::get_stdin_string() { - 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); + } } void OS_Windows::enable_for_stealing_focus(ProcessID pid) {