fix(libc): set EILSEQ in btowc for bytes that cannot start a character

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SNqSvnFwRBz3D76n476yw6
This commit is contained in:
hypermistandClaude Opus 5.5 committed 2026-10-23 13:32:50 +13:00
1 parent 3563fa21c4
commit 4d1e7d8b60
2 files changed
+15 -1

No files matched your search

+5 -1
View File
@@ -1,4 +1,5 @@
#include "prx/libc/include/general/VabiMacros.hpp"
#include <cerrno>
#include <cstddef>
#include <cstdint>
#include <cstring>
@@ -148,7 +149,10 @@ std::uint32_t APS5_VABI towupper_nid_postfix(std::uint32_t c) {
std::uint32_t APS5_VABI btowc_nid_postfix(int c) {
const auto byte = static_cast<unsigned char>(c);
return c == -1 || byte >= 0x80 ? GuestRune::Weof : byte;
if (c == -1) return GuestRune::Weof;
if (byte < 0x80) return byte;
if (byte < 0xc0 || byte >= 0xf0) errno = 86;
return GuestRune::Weof;
}
int APS5_VABI wctob_nid_postfix(std::uint32_t c) {
+10
View File
@@ -149,5 +149,15 @@ int main() {
}
errno = 0;
Require(towctrans_nid_postfix('A', 0) == 'A' && towctrans_nid_postfix('a', 3) == 'a' && errno == 0);
for (int c = -300; c < 0x1200; ++c) {
const auto byte = static_cast<unsigned char>(c);
errno = 0;
const std::uint32_t wide = btowc_nid_postfix(c);
const bool invalidLead = c != -1 && ((byte >= 0x80 && byte < 0xc0) || byte >= 0xf0);
Require(wide == (c != -1 && byte < 0x80 ? byte : 0xffffffffu) && errno == (invalidLead ? 86 : 0));
}
errno = 7;
Require(btowc_nid_postfix(0xc3) == 0xffffffff && btowc_nid_postfix(0xef) == 0xffffffff && btowc_nid_postfix(-1) == 0xffffffff && errno == 7);
Require(btowc_nid_postfix(0x41) == 'A' && errno == 7);
return 0;
}