]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: force Windows to always use US English error messages
authorShenghou Ma <minux.ma@gmail.com>
Sun, 19 Feb 2012 22:51:25 +0000 (09:51 +1100)
committerAlex Brainman <alex.brainman@gmail.com>
Sun, 19 Feb 2012 22:51:25 +0000 (09:51 +1100)
Fixes #1834.

R=rsc, alex.brainman
CC=golang-dev
https://golang.org/cl/5673068

src/pkg/syscall/syscall_windows.go
src/pkg/syscall/ztypes_windows.go

index 00208d6bc03f0488256e0fc12707bdd2fd1ac823..fde3bef50e04f0e62c5c35e249fca3a998c1944f 100644 (file)
@@ -77,6 +77,8 @@ func Getpagesize() int { return 4096 }
 // Errno is the Windows error number.
 type Errno uintptr
 
+func langid(pri, sub uint16) uint32 { return uint32(sub)<<10 | uint32(pri) }
+
 func (e Errno) Error() string {
        // deal with special go errors
        idx := int(e - APPLICATION_ERROR)
@@ -86,7 +88,7 @@ func (e Errno) Error() string {
        // ask windows for the remaining errors
        var flags uint32 = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_IGNORE_INSERTS
        b := make([]uint16, 300)
-       n, err := FormatMessage(flags, 0, uint32(e), 0, b, nil)
+       n, err := FormatMessage(flags, 0, uint32(e), langid(LANG_ENGLISH, SUBLANG_ENGLISH_US), b, nil)
        if err != nil {
                return "error " + itoa(int(e)) + " (FormatMessage failed with err=" + itoa(int(err.(Errno))) + ")"
        }
index 9a9112c1fa1625099cbbd44f43490e8e52c4c4d3..5a7a50c08dbc7ea1ea97d3c5427632571661df94 100644 (file)
@@ -116,6 +116,9 @@ const (
        FILE_CURRENT = 1
        FILE_END     = 2
 
+       LANG_ENGLISH       = 0x09
+       SUBLANG_ENGLISH_US = 0x01
+
        FORMAT_MESSAGE_ALLOCATE_BUFFER = 256
        FORMAT_MESSAGE_IGNORE_INSERTS  = 512
        FORMAT_MESSAGE_FROM_STRING     = 1024