Commit d75acd67 authored by Alex Brainman's avatar Alex Brainman Committed by Russ Cox

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/17997Reviewed-by: default avatarYasuhiro MATSUMOTO <mattn.jp@gmail.com>
Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 5755c011
...@@ -139,5 +139,5 @@ func Rename(oldpath, newpath string) error { ...@@ -139,5 +139,5 @@ func Rename(oldpath, newpath string) error {
return MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING) return MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING)
} }
//sys GetACP() (acp uint, err error) = kernel32.GetACP //sys GetACP() (acp uint32) = kernel32.GetACP
//sys MultiByteToWideChar(codePage uint, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int, err error) = kernel32.MultiByteToWideChar //sys MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) = kernel32.MultiByteToWideChar
...@@ -50,23 +50,16 @@ func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) { ...@@ -50,23 +50,16 @@ func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) {
return return
} }
func MultiByteToWideChar(codePage uint, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int, err error) { func GetACP() (acp uint32) {
r0, _, e1 := syscall.Syscall6(procMultiByteToWideChar.Addr(), 6, uintptr(codePage), uintptr(dwFlags), uintptr(unsafe.Pointer(str)), uintptr(nstr), uintptr(unsafe.Pointer(wchar)), uintptr(nwchar)) r0, _, _ := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0)
nwrite = int(r0) acp = uint32(r0)
if nwrite == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return return
} }
func GetACP() (acp uint, err error) { func MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) {
r0, _, e1 := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0) r0, _, e1 := syscall.Syscall6(procMultiByteToWideChar.Addr(), 6, uintptr(codePage), uintptr(dwFlags), uintptr(unsafe.Pointer(str)), uintptr(nstr), uintptr(unsafe.Pointer(wchar)), uintptr(nwchar))
acp = uint(r0) nwrite = int32(r0)
if acp == 0 { if nwrite == 0 {
if e1 != 0 { if e1 != 0 {
err = error(e1) err = error(e1)
} else { } else {
......
...@@ -279,10 +279,7 @@ func (f *File) readConsole(b []byte) (n int, err error) { ...@@ -279,10 +279,7 @@ func (f *File) readConsole(b []byte) (n int, err error) {
if len(b) > 0 { if len(b) > 0 {
pmb = &mbytes[0] pmb = &mbytes[0]
} }
acp, err := windows.GetACP() acp := windows.GetACP()
if err != nil {
return 0, err
}
nwc, err := windows.MultiByteToWideChar(acp, 2, pmb, int32(nmb), nil, 0) nwc, err := windows.MultiByteToWideChar(acp, 2, pmb, int32(nmb), nil, 0)
if err != nil { if err != nil {
return 0, err return 0, err
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment