]> Cypherpunks repositories - gostls13.git/commitdiff
internal/syscall/windows: correct GetACP and MultiByteToWideChar
authorAlex Brainman <alex.brainman@gmail.com>
Mon, 21 Dec 2015 05:16:06 +0000 (16:16 +1100)
committerRuss Cox <rsc@golang.org>
Fri, 8 Jan 2016 16:15:59 +0000 (16:15 +0000)
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>
src/internal/syscall/windows/syscall_windows.go
src/internal/syscall/windows/zsyscall_windows.go
src/os/file_windows.go

index e5c1cd600c3d94329ff97a5bcab848331ff1ab52..165e8945ec37a547d93c15992219eac2de0c5e4e 100644 (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
index fd614f88976a4d7e2ac152aaf3643cf0040439a4..de41786c76e77950ffa5940c9023fc93b5b8e8a7 100644 (file)
@@ -50,23 +50,16 @@ 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) {
-       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)
-       if nwrite == 0 {
-               if e1 != 0 {
-                       err = error(e1)
-               } else {
-                       err = syscall.EINVAL
-               }
-       }
+func GetACP() (acp uint32) {
+       r0, _, _ := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0)
+       acp = uint32(r0)
        return
 }
 
-func GetACP() (acp uint, err error) {
-       r0, _, e1 := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0)
-       acp = uint(r0)
-       if acp == 0 {
+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 = int32(r0)
+       if nwrite == 0 {
                if e1 != 0 {
                        err = error(e1)
                } else {
index bda495ec8c9df7a7ad1350b8f4a1987e448113bf..9b0458552c28dd1c3d15951a9dc18f92d99691b9 100644 (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