From 19df2934633234265ade2c8dcee925ea2b136dc4 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Fri, 23 Jan 2026 15:11:55 +0800 Subject: [PATCH] fix: fix macos build issue again --- src/yycc/encoding/iconv.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/yycc/encoding/iconv.cpp b/src/yycc/encoding/iconv.cpp index 92799ac..8b83d0f 100644 --- a/src/yycc/encoding/iconv.cpp +++ b/src/yycc/encoding/iconv.cpp @@ -3,6 +3,7 @@ #if defined(YYCC_FEAT_ICONV) #include "../macro/endian_detector.hpp" +#include "../macro/os_detector.hpp" #include #include #include @@ -202,11 +203,14 @@ namespace yycc::encoding::iconv { // If we use UTF16 or UTF32 code name directly, it will produce a BOM at data head. // That's not what we expected. // So we need manually check runtime endian and explicitly specify endian in code name. + // + // Also, at the same time, iconv on macOS do not support "WCHAR_T" encoding, + // so we need manually set it as UTF32 encoding. + // See https://developer.apple.com/forums/thread/811508 for more infos. using namespace std::literals::string_view_literals; constexpr auto UTF8_CODENAME_LITERAL = "UTF-8"sv; - constexpr auto WCHAR_CODENAME_LITERAL = "WCHAR_T"sv; constexpr auto UTF16_CODENAME_LITERAL = #if defined(YYCC_ENDIAN_LITTLE) "UTF-16LE"sv; @@ -219,6 +223,13 @@ namespace yycc::encoding::iconv { #else "UTF-32BE"sv; #endif + constexpr auto WCHAR_CODENAME_LITERAL = +#if defined(YYCC_OS_MACOS) + UTF32_CODENAME_LITERAL; + static_assert(sizeof(wchar_t) == sizeof(char32_t), "unexpected wchar_t size"); +#else + "WCHAR_T"sv; +#endif // TODO: // There is a memory copy in this function. Consider optimizing it in future.