go: internal/syscall/windows: GetACP returns wrong codepage
-
What version of Go are you using (
go version
)? 1.7 -
What operating system and processor architecture are you using (
go env
)? Windows, arm64go env
:set GOARCH=amd64 set GOBIN= set GOEXE=.exe set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOOS=windows set GOPATH=C:\dev\golang set GORACE= set GOROOT=C:\Go set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64 set CC=gcc set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Tobias\AppData\Local\Temp\go-build473402786=/tmp/go-build -gno-record-gcc-switches set CXX=g++ set CGO_ENABLED=1
-
What did you do? I wrote a program which just reads bytes from
os.Stdin
and prints their values as Hex to Stdout. I started the program, typed aä
to the console and pressed enter. -
What did you expect to see? I expected to see the correct UTF-8 sequence for a
ä
which isC3 A4
-
What did you see instead? I see the Hex-sequence
E2 80 9E
I found that internal/syscall/windows GetACP() returns 1252 even though I can verify that the ä
is encoded in CP850. Because of this wrongly returned codepage, Stdin.readConsole tries to decode the character from 1252 to UTF-8 instead of from 850 to UTF-8. As you see in my Post on Stackoverflow, when I read from stdin through CGO I get the byte 0x84 which is the value for a ä
in CP850, it should’ve been 0xE4 if it were in 1252. The value 0x84 decoded from golang.org/x/text/encoding/charmap
.CodePage850
decodes to the correct UTF-8 character.
chcp
tells me that the active codepage is 850.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 2
- Comments: 23 (14 by maintainers)
@mattn Sure, I’ll try. but don’t expect too much.
@mattn I will let you try and fix this, since I have nothing but English around me.
Alex