Commit 7ebcf5ea authored by Alex Brainman's avatar Alex Brainman

syscall: warn not to use FormatMessage

Fixes #11147

Change-Id: Ib31160946a53f6f9b11daea211ff04d186b51b3f
Reviewed-on: https://go-review.googlesource.com/12067Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent af8297da
......@@ -82,6 +82,14 @@ type Errno uintptr
func langid(pri, sub uint16) uint32 { return uint32(sub)<<10 | uint32(pri) }
// FormatMessage is deprecated (msgsrc should be uintptr, not uint32, but can
// not be changed due to the Go 1 compatibility guarantee).
//
// Deprecated: Use FormatMessage from golang.org/x/sys/windows instead.
func FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) {
return formatMessage(flags, uintptr(msgsrc), msgid, langid, buf, args)
}
func (e Errno) Error() string {
// deal with special go errors
idx := int(e - APPLICATION_ERROR)
......@@ -91,9 +99,9 @@ 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), langid(LANG_ENGLISH, SUBLANG_ENGLISH_US), b, nil)
n, err := formatMessage(flags, 0, uint32(e), langid(LANG_ENGLISH, SUBLANG_ENGLISH_US), b, nil)
if err != nil {
n, err = FormatMessage(flags, 0, uint32(e), 0, b, nil)
n, err = formatMessage(flags, 0, uint32(e), 0, b, nil)
if err != nil {
return "winapi error #" + itoa(int(e))
}
......@@ -136,7 +144,7 @@ func NewCallbackCDecl(fn interface{}) uintptr {
//sys FreeLibrary(handle Handle) (err error)
//sys GetProcAddress(module Handle, procname string) (proc uintptr, err error)
//sys GetVersion() (ver uint32, err error)
//sys FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) = FormatMessageW
//sys formatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) = FormatMessageW
//sys ExitProcess(exitcode uint32)
//sys CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes, createmode uint32, attrs uint32, templatefile int32) (handle Handle, err error) [failretval==InvalidHandle] = CreateFileW
//sys ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error)
......
......@@ -240,7 +240,7 @@ func GetVersion() (ver uint32, err error) {
return
}
func FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) {
func formatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) {
var _p0 *uint16
if len(buf) > 0 {
_p0 = &buf[0]
......
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