diff options
| author | chooyy <[email protected]> | 2026-06-18 22:59:49 +0800 |
|---|---|---|
| committer | chooyy <[email protected]> | 2026-06-18 22:59:49 +0800 |
| commit | 62fa217c932307158cce7534c96de6fdb80735de (patch) | |
| tree | 7c97aeedea3c86a89b8fcc931b1cbf07f9d375ef | |
| parent | 115e8042a9811b1248b339b2661b457a24e7bd9f (diff) | |
strip trailing \r\n
| -rw-r--r-- | core/src/xmake/os/strerror.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/core/src/xmake/os/strerror.c b/core/src/xmake/os/strerror.c index a55ff6d2f..e8c461ea7 100644 --- a/core/src/xmake/os/strerror.c +++ b/core/src/xmake/os/strerror.c @@ -67,10 +67,14 @@ tb_int_t xm_os_strerror(lua_State *lua) { DWORD error_code = GetLastError(); tb_char_t strerr[128 * 2] = { 0 }; tb_wchar_t wstrerr[128] = { 0 }; + tb_size_t len = 0; if (FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), wstrerr, tb_arrayn(wstrerr), NULL) && - tb_wcslen(wstrerr) > 0) { + (len = tb_wcslen(wstrerr)) > 0) { + while (len > 0 && (wstrerr[len - 1] == L'\r' || wstrerr[len - 1] == L'\n')) { + wstrerr[--len] = L'\0'; + } WideCharToMultiByte(CP_UTF8, 0, wstrerr, -1, strerr, sizeof(strerr), tb_null, tb_null); } if (strerr[0] == '\0') { |
