From 2ec126c504e39ff21605298d3e79d62b26804b31 Mon Sep 17 00:00:00 2001 From: lixianjing Date: Mon, 21 Aug 2023 11:35:50 +0800 Subject: [PATCH] platform windows support output utf8 text to console --- docs/changes.md | 1 + src/platforms/pc/platform.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/changes.md b/docs/changes.md index f8a7c8bc9..e1e35714d 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -6,6 +6,7 @@ * 增加函数tk\_to\_utf8\_argv * 增加函数tk\_free\_utf8\_argv * 增加宏MAIN/END\_MAIN + * 完善Windows平台初始化,让Console输出支持UTF8。 2023/08/16 * 增加函数str\_equal/wstr\_eq/wstr\_create/wstr\_destroy/wstr\_append\_more等函数 diff --git a/src/platforms/pc/platform.c b/src/platforms/pc/platform.c index 4c7ca7f6a..6f1821d52 100644 --- a/src/platforms/pc/platform.c +++ b/src/platforms/pc/platform.c @@ -51,7 +51,6 @@ static int32_t get_local_timezone() { return timezone; } - int gettimeofday(struct timeval* tp, void* tzp) { time_t clock; struct tm tm; @@ -254,6 +253,19 @@ ret_t platform_prepare(void) { stm_time_init(); +#ifdef WIN32 + /*let console output support utf8 text*/ + if (!IsValidCodePage(CP_UTF8)) { + log_debug("Not support UTF-8 output\n"); + } + if (!SetConsoleCP(CP_UTF8)) { + log_debug("Not support UTF-8 output\n"); + } + if (!SetConsoleOutputCP(CP_UTF8)) { + log_debug("Not support UTF-8 output\n"); + } +#endif /*WIN32*/ + #ifndef HAS_STD_MALLOC #ifndef TK_HEAP_MEM_SIZE #define TK_HEAP_MEM_SIZE 12 * 1024 * 1024