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