internal/syscall/windows: correct GetACP and MultiByteToWideChar

CL 4310 introduced these functions, but their
implementation does not match with their published
documentation. Correct the implementation.

Change-Id: I285e41f9c7c5fc4e550ff59b0adb8b2bcbf6737a
Reviewed-on: https://go-review.googlesource.com/17997
Reviewed-by: Yasuhiro MATSUMOTO <mattn.jp@gmail.com>
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Alex Brainman 2015-12-21 16:16:06 +11:00 committed by Russ Cox
parent 5755c011de
commit d75acd67ec
3 changed files with 11 additions and 21 deletions

View File

@ -139,5 +139,5 @@ func Rename(oldpath, newpath string) error {
return MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING)
}
//sys GetACP() (acp uint, err error) = kernel32.GetACP
//sys MultiByteToWideChar(codePage uint, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int, err error) = kernel32.MultiByteToWideChar
//sys GetACP() (acp uint32) = kernel32.GetACP
//sys MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) = kernel32.MultiByteToWideChar

View File

@ -50,9 +50,15 @@ func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) {
return
}
func MultiByteToWideChar(codePage uint, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int, err error) {
func GetACP() (acp uint32) {
r0, _, _ := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0)
acp = uint32(r0)
return
}
func MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) {
r0, _, e1 := syscall.Syscall6(procMultiByteToWideChar.Addr(), 6, uintptr(codePage), uintptr(dwFlags), uintptr(unsafe.Pointer(str)), uintptr(nstr), uintptr(unsafe.Pointer(wchar)), uintptr(nwchar))
nwrite = int(r0)
nwrite = int32(r0)
if nwrite == 0 {
if e1 != 0 {
err = error(e1)
@ -62,16 +68,3 @@ func MultiByteToWideChar(codePage uint, dwFlags uint32, str *byte, nstr int32, w
}
return
}
func GetACP() (acp uint, err error) {
r0, _, e1 := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0)
acp = uint(r0)
if acp == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
}

View File

@ -279,10 +279,7 @@ func (f *File) readConsole(b []byte) (n int, err error) {
if len(b) > 0 {
pmb = &mbytes[0]
}
acp, err := windows.GetACP()
if err != nil {
return 0, err
}
acp := windows.GetACP()
nwc, err := windows.MultiByteToWideChar(acp, 2, pmb, int32(nmb), nil, 0)
if err != nil {
return 0, err