ww source: align UTF-8 BOM placement

This commit is contained in:
2026-08-21 20:34:10 +09:00
parent ee4573bf55
commit 9381f8fb8e
11 changed files with 764 additions and 5 deletions

View File

@@ -5594,7 +5594,19 @@ fn sepemitbody(fd: i32, path: *u8, modpath: *u8) i32 = {
return -1;
};
};
if (!sepwriteall(fd, bufp, blen)
// Each physical source owns its own first-codepoint position. The compiler
// sees one synthetic aggregate, so replace the optional UTF-8 BOM with
// position-preserving whitespace rather than making it a mid-unit BOM.
let off: u64 = 0u64;
if (blen >= 3u64 && bufp[0] == 0xefu8
&& bufp[1] == 0xbbu8 && bufp[2] == 0xbfu8) {
off = 3u64;
};
if (off != 0u64 && !sepwriteall(fd, " ".ptr, 3u64)) {
cerr("ww: cannot write package unit\n");
return -1;
};
if (!sepwriteall(fd, bufp + off, blen - off)
|| !sepwriteall(fd, "\n".ptr, 1u64)) {
cerr("ww: cannot write package unit\n");
return -1;