summaryrefslogtreecommitdiffstats
path: root/platform/windows/windows_terminal_logger.cpp
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2024-05-20 13:24:10 +0300
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2024-05-20 14:23:17 +0300
commit497f65fa5037d3c02a5267ab46c866b35428d8c4 (patch)
treef6602035d6908a8a2bd528a311e8d477a55f7c6f /platform/windows/windows_terminal_logger.cpp
parentdaa81bbb7d1c6d75d1711595604178ee62a5801d (diff)
downloadredot-engine-497f65fa5037d3c02a5267ab46c866b35428d8c4.tar.gz
[Windows] Use CRLF in the terminal prints.
Diffstat (limited to 'platform/windows/windows_terminal_logger.cpp')
-rw-r--r--platform/windows/windows_terminal_logger.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/platform/windows/windows_terminal_logger.cpp b/platform/windows/windows_terminal_logger.cpp
index 6fc33afe99..6c54faa13a 100644
--- a/platform/windows/windows_terminal_logger.cpp
+++ b/platform/windows/windows_terminal_logger.cpp
@@ -42,20 +42,30 @@ void WindowsTerminalLogger::logv(const char *p_format, va_list p_list, bool p_er
return;
}
- const unsigned int BUFFER_SIZE = 16384;
- char buf[BUFFER_SIZE + 1]; // +1 for the terminating character
- int len = vsnprintf(buf, BUFFER_SIZE, p_format, p_list);
- if (len <= 0) {
- return;
+ const int static_buffer_size = 1024;
+ char static_buf[static_buffer_size];
+ char *buf = static_buf;
+ va_list list_copy;
+ va_copy(list_copy, p_list);
+ int len = vsnprintf(buf, static_buffer_size, p_format, p_list);
+ if (len >= static_buffer_size) {
+ buf = (char *)memalloc(len + 1);
+ len = vsnprintf(buf, len + 1, p_format, list_copy);
+ }
+ va_end(list_copy);
+
+ String str_buf = String::utf8(buf, len).replace("\r\n", "\n").replace("\n", "\r\n");
+ if (len >= static_buffer_size) {
+ memfree(buf);
}
- if ((unsigned int)len >= BUFFER_SIZE) {
- len = BUFFER_SIZE; // Output is too big, will be truncated
+ CharString cstr_buf = str_buf.utf8();
+ if (cstr_buf.length() == 0) {
+ return;
}
- buf[len] = 0;
DWORD written = 0;
HANDLE h = p_err ? GetStdHandle(STD_ERROR_HANDLE) : GetStdHandle(STD_OUTPUT_HANDLE);
- WriteFile(h, &buf[0], len, &written, nullptr);
+ WriteFile(h, cstr_buf.ptr(), cstr_buf.length(), &written, nullptr);
#ifdef DEBUG_ENABLED
FlushFileBuffers(h);