Commit 4faa336c authored by Rob Pike's avatar Rob Pike

go.sys/windows: use syscall.Errno for windows errors

If we use a local type, it won't compare properly with errors from
the rest of the standard library. Errors are the one type from syscall
that propagates through the system, so it's important to have only
one type for them.

mkerrors_windows.sh is gone, so:
 - rename zerrors_windows.go and delete its DO NOT EDIT mark
 - delete the contentless zerrors_windows_*.go files

LGTM=rsc
R=rsc
CC=alex.brainman, golang-codereviews
https://golang.org/cl/122600043
parent b87d025a
// mkerrors_windows.sh -m32
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package windows
import "syscall"
// Go names for Windows errors.
const (
ENOENT Errno = ERROR_FILE_NOT_FOUND
ENOTDIR Errno = ERROR_PATH_NOT_FOUND
ENOENT syscall.Errno = ERROR_FILE_NOT_FOUND
ENOTDIR syscall.Errno = ERROR_PATH_NOT_FOUND
)
// Windows reserves errors >= 1<<29 for application use.
......@@ -14,7 +17,7 @@ const APPLICATION_ERROR = 1 << 29
// Invented values to support what package os and others expects.
const (
E2BIG Errno = APPLICATION_ERROR + iota
E2BIG syscall.Errno = APPLICATION_ERROR + iota
EACCES
EADDRINUSE
EADDRNOTAVAIL
......
......@@ -271,7 +271,7 @@ func (r *Rets) useLongHandleErrorCode(retvar string) string {
// SetErrorCode returns source code that sets return parameters.
func (r *Rets) SetErrorCode() string {
const code = `if r0 != 0 {
%s = %sErrno(r0)
%s = syscall.Errno(r0)
}`
if r.Name == "" && !r.ReturnsError {
return ""
......@@ -280,7 +280,7 @@ func (r *Rets) SetErrorCode() string {
return r.useLongHandleErrorCode("r1")
}
if r.Type == "error" {
return fmt.Sprintf(code, r.Name, windowsdot())
return fmt.Sprintf(code, r.Name)
}
s := ""
switch {
......
......@@ -17,21 +17,10 @@
// For details of the functions and data types in this package consult
// the manuals for the appropriate operating system.
// These calls return err == nil to indicate success; otherwise
// err is an operating system error describing the failure.
// That error has type windows.Errno.
// err represents an operating system error describing the failure and
// holds a value of type syscall.Errno.
package windows
// StringByteSlice is deprecated. Use ByteSliceFromString instead.
// If s contains a NUL byte this function panics instead of
// returning an error.
func StringByteSlice(s string) []byte {
a, err := ByteSliceFromString(s)
if err != nil {
panic("windows: string with NUL passed to StringByteSlice")
}
return a
}
// ByteSliceFromString returns a NUL-terminated slice of bytes
// containing the text of s. If s contains a NUL byte at any
// location, it returns (nil, EINVAL).
......@@ -46,11 +35,6 @@ func ByteSliceFromString(s string) ([]byte, error) {
return a, nil
}
// StringBytePtr is deprecated. Use BytePtrFromString instead.
// If s contains a NUL byte this function panics instead of
// returning an error.
func StringBytePtr(s string) *byte { return &StringByteSlice(s)[0] }
// BytePtrFromString returns a pointer to a NUL-terminated array of
// bytes containing the text of s. If s contains a NUL byte at any
// location, it returns (nil, EINVAL).
......
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package windows
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package windows
......@@ -165,7 +165,7 @@ var (
func GetLastError() (lasterr error) {
r0, _, _ := syscall.Syscall(procGetLastError.Addr(), 0, 0, 0, 0)
if r0 != 0 {
lasterr = Errno(r0)
lasterr = syscall.Errno(r0)
}
return
}
......@@ -1182,7 +1182,7 @@ func CertVerifyCertificateChainPolicy(policyOID uintptr, chain *CertChainContext
func RegOpenKeyEx(key Handle, subkey *uint16, options uint32, desiredAccess uint32, result *Handle) (regerrno error) {
r0, _, _ := syscall.Syscall6(procRegOpenKeyExW.Addr(), 5, uintptr(key), uintptr(unsafe.Pointer(subkey)), uintptr(options), uintptr(desiredAccess), uintptr(unsafe.Pointer(result)), 0)
if r0 != 0 {
regerrno = Errno(r0)
regerrno = syscall.Errno(r0)
}
return
}
......@@ -1190,7 +1190,7 @@ func RegOpenKeyEx(key Handle, subkey *uint16, options uint32, desiredAccess uint
func RegCloseKey(key Handle) (regerrno error) {
r0, _, _ := syscall.Syscall(procRegCloseKey.Addr(), 1, uintptr(key), 0, 0)
if r0 != 0 {
regerrno = Errno(r0)
regerrno = syscall.Errno(r0)
}
return
}
......@@ -1198,7 +1198,7 @@ func RegCloseKey(key Handle) (regerrno error) {
func RegQueryInfoKey(key Handle, class *uint16, classLen *uint32, reserved *uint32, subkeysLen *uint32, maxSubkeyLen *uint32, maxClassLen *uint32, valuesLen *uint32, maxValueNameLen *uint32, maxValueLen *uint32, saLen *uint32, lastWriteTime *Filetime) (regerrno error) {
r0, _, _ := syscall.Syscall12(procRegQueryInfoKeyW.Addr(), 12, uintptr(key), uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(classLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(subkeysLen)), uintptr(unsafe.Pointer(maxSubkeyLen)), uintptr(unsafe.Pointer(maxClassLen)), uintptr(unsafe.Pointer(valuesLen)), uintptr(unsafe.Pointer(maxValueNameLen)), uintptr(unsafe.Pointer(maxValueLen)), uintptr(unsafe.Pointer(saLen)), uintptr(unsafe.Pointer(lastWriteTime)))
if r0 != 0 {
regerrno = Errno(r0)
regerrno = syscall.Errno(r0)
}
return
}
......@@ -1206,7 +1206,7 @@ func RegQueryInfoKey(key Handle, class *uint16, classLen *uint32, reserved *uint
func RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, classLen *uint32, lastWriteTime *Filetime) (regerrno error) {
r0, _, _ := syscall.Syscall9(procRegEnumKeyExW.Addr(), 8, uintptr(key), uintptr(index), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(classLen)), uintptr(unsafe.Pointer(lastWriteTime)), 0)
if r0 != 0 {
regerrno = Errno(r0)
regerrno = syscall.Errno(r0)
}
return
}
......@@ -1214,7 +1214,7 @@ func RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reser
func RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) {
r0, _, _ := syscall.Syscall6(procRegQueryValueExW.Addr(), 6, uintptr(key), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(valtype)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(buflen)))
if r0 != 0 {
regerrno = Errno(r0)
regerrno = syscall.Errno(r0)
}
return
}
......@@ -1337,7 +1337,7 @@ func CreateHardLink(filename *uint16, existingfilename *uint16, reserved uintptr
func WSAStartup(verreq uint32, data *WSAData) (sockerr error) {
r0, _, _ := syscall.Syscall(procWSAStartup.Addr(), 2, uintptr(verreq), uintptr(unsafe.Pointer(data)), 0)
if r0 != 0 {
sockerr = Errno(r0)
sockerr = syscall.Errno(r0)
}
return
}
......@@ -1625,7 +1625,7 @@ func DnsQuery(name string, qtype uint16, options uint32, extra *byte, qrs **DNSR
}
r0, _, _ := syscall.Syscall6(procDnsQuery_W.Addr(), 6, uintptr(unsafe.Pointer(_p0)), uintptr(qtype), uintptr(options), uintptr(unsafe.Pointer(extra)), uintptr(unsafe.Pointer(qrs)), uintptr(unsafe.Pointer(pr)))
if r0 != 0 {
status = Errno(r0)
status = syscall.Errno(r0)
}
return
}
......@@ -1638,7 +1638,7 @@ func DnsRecordListFree(rl *DNSRecord, freetype uint32) {
func GetAddrInfoW(nodename *uint16, servicename *uint16, hints *AddrinfoW, result **AddrinfoW) (sockerr error) {
r0, _, _ := syscall.Syscall6(procGetAddrInfoW.Addr(), 4, uintptr(unsafe.Pointer(nodename)), uintptr(unsafe.Pointer(servicename)), uintptr(unsafe.Pointer(hints)), uintptr(unsafe.Pointer(result)), 0, 0)
if r0 != 0 {
sockerr = Errno(r0)
sockerr = syscall.Errno(r0)
}
return
}
......@@ -1651,7 +1651,7 @@ func FreeAddrInfoW(addrinfo *AddrinfoW) {
func GetIfEntry(pIfRow *MibIfRow) (errcode error) {
r0, _, _ := syscall.Syscall(procGetIfEntry.Addr(), 1, uintptr(unsafe.Pointer(pIfRow)), 0, 0)
if r0 != 0 {
errcode = Errno(r0)
errcode = syscall.Errno(r0)
}
return
}
......@@ -1659,7 +1659,7 @@ func GetIfEntry(pIfRow *MibIfRow) (errcode error) {
func GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode error) {
r0, _, _ := syscall.Syscall(procGetAdaptersInfo.Addr(), 2, uintptr(unsafe.Pointer(ai)), uintptr(unsafe.Pointer(ol)), 0)
if r0 != 0 {
errcode = Errno(r0)
errcode = syscall.Errno(r0)
}
return
}
......@@ -1716,7 +1716,7 @@ func GetUserNameEx(nameFormat uint32, nameBuffre *uint16, nSize *uint32) (err er
func NetUserGetInfo(serverName *uint16, userName *uint16, level uint32, buf **byte) (neterr error) {
r0, _, _ := syscall.Syscall6(procNetUserGetInfo.Addr(), 4, uintptr(unsafe.Pointer(serverName)), uintptr(unsafe.Pointer(userName)), uintptr(level), uintptr(unsafe.Pointer(buf)), 0, 0)
if r0 != 0 {
neterr = Errno(r0)
neterr = syscall.Errno(r0)
}
return
}
......@@ -1724,7 +1724,7 @@ func NetUserGetInfo(serverName *uint16, userName *uint16, level uint32, buf **by
func NetGetJoinInformation(server *uint16, name **uint16, bufType *uint32) (neterr error) {
r0, _, _ := syscall.Syscall(procNetGetJoinInformation.Addr(), 3, uintptr(unsafe.Pointer(server)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(bufType)))
if r0 != 0 {
neterr = Errno(r0)
neterr = syscall.Errno(r0)
}
return
}
......@@ -1732,7 +1732,7 @@ func NetGetJoinInformation(server *uint16, name **uint16, bufType *uint32) (nete
func NetApiBufferFree(buf *byte) (neterr error) {
r0, _, _ := syscall.Syscall(procNetApiBufferFree.Addr(), 1, uintptr(unsafe.Pointer(buf)), 0, 0)
if r0 != 0 {
neterr = Errno(r0)
neterr = syscall.Errno(r0)
}
return
}
......
......@@ -165,7 +165,7 @@ var (
func GetLastError() (lasterr error) {
r0, _, _ := syscall.Syscall(procGetLastError.Addr(), 0, 0, 0, 0)
if r0 != 0 {
lasterr = Errno(r0)
lasterr = syscall.Errno(r0)
}
return
}
......@@ -1182,7 +1182,7 @@ func CertVerifyCertificateChainPolicy(policyOID uintptr, chain *CertChainContext
func RegOpenKeyEx(key Handle, subkey *uint16, options uint32, desiredAccess uint32, result *Handle) (regerrno error) {
r0, _, _ := syscall.Syscall6(procRegOpenKeyExW.Addr(), 5, uintptr(key), uintptr(unsafe.Pointer(subkey)), uintptr(options), uintptr(desiredAccess), uintptr(unsafe.Pointer(result)), 0)
if r0 != 0 {
regerrno = Errno(r0)
regerrno = syscall.Errno(r0)
}
return
}
......@@ -1190,7 +1190,7 @@ func RegOpenKeyEx(key Handle, subkey *uint16, options uint32, desiredAccess uint
func RegCloseKey(key Handle) (regerrno error) {
r0, _, _ := syscall.Syscall(procRegCloseKey.Addr(), 1, uintptr(key), 0, 0)
if r0 != 0 {
regerrno = Errno(r0)
regerrno = syscall.Errno(r0)
}
return
}
......@@ -1198,7 +1198,7 @@ func RegCloseKey(key Handle) (regerrno error) {
func RegQueryInfoKey(key Handle, class *uint16, classLen *uint32, reserved *uint32, subkeysLen *uint32, maxSubkeyLen *uint32, maxClassLen *uint32, valuesLen *uint32, maxValueNameLen *uint32, maxValueLen *uint32, saLen *uint32, lastWriteTime *Filetime) (regerrno error) {
r0, _, _ := syscall.Syscall12(procRegQueryInfoKeyW.Addr(), 12, uintptr(key), uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(classLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(subkeysLen)), uintptr(unsafe.Pointer(maxSubkeyLen)), uintptr(unsafe.Pointer(maxClassLen)), uintptr(unsafe.Pointer(valuesLen)), uintptr(unsafe.Pointer(maxValueNameLen)), uintptr(unsafe.Pointer(maxValueLen)), uintptr(unsafe.Pointer(saLen)), uintptr(unsafe.Pointer(lastWriteTime)))
if r0 != 0 {
regerrno = Errno(r0)
regerrno = syscall.Errno(r0)
}
return
}
......@@ -1206,7 +1206,7 @@ func RegQueryInfoKey(key Handle, class *uint16, classLen *uint32, reserved *uint
func RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, classLen *uint32, lastWriteTime *Filetime) (regerrno error) {
r0, _, _ := syscall.Syscall9(procRegEnumKeyExW.Addr(), 8, uintptr(key), uintptr(index), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(classLen)), uintptr(unsafe.Pointer(lastWriteTime)), 0)
if r0 != 0 {
regerrno = Errno(r0)
regerrno = syscall.Errno(r0)
}
return
}
......@@ -1214,7 +1214,7 @@ func RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reser
func RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) {
r0, _, _ := syscall.Syscall6(procRegQueryValueExW.Addr(), 6, uintptr(key), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(valtype)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(buflen)))
if r0 != 0 {
regerrno = Errno(r0)
regerrno = syscall.Errno(r0)
}
return
}
......@@ -1337,7 +1337,7 @@ func CreateHardLink(filename *uint16, existingfilename *uint16, reserved uintptr
func WSAStartup(verreq uint32, data *WSAData) (sockerr error) {
r0, _, _ := syscall.Syscall(procWSAStartup.Addr(), 2, uintptr(verreq), uintptr(unsafe.Pointer(data)), 0)
if r0 != 0 {
sockerr = Errno(r0)
sockerr = syscall.Errno(r0)
}
return
}
......@@ -1625,7 +1625,7 @@ func DnsQuery(name string, qtype uint16, options uint32, extra *byte, qrs **DNSR
}
r0, _, _ := syscall.Syscall6(procDnsQuery_W.Addr(), 6, uintptr(unsafe.Pointer(_p0)), uintptr(qtype), uintptr(options), uintptr(unsafe.Pointer(extra)), uintptr(unsafe.Pointer(qrs)), uintptr(unsafe.Pointer(pr)))
if r0 != 0 {
status = Errno(r0)
status = syscall.Errno(r0)
}
return
}
......@@ -1638,7 +1638,7 @@ func DnsRecordListFree(rl *DNSRecord, freetype uint32) {
func GetAddrInfoW(nodename *uint16, servicename *uint16, hints *AddrinfoW, result **AddrinfoW) (sockerr error) {
r0, _, _ := syscall.Syscall6(procGetAddrInfoW.Addr(), 4, uintptr(unsafe.Pointer(nodename)), uintptr(unsafe.Pointer(servicename)), uintptr(unsafe.Pointer(hints)), uintptr(unsafe.Pointer(result)), 0, 0)
if r0 != 0 {
sockerr = Errno(r0)
sockerr = syscall.Errno(r0)
}
return
}
......@@ -1651,7 +1651,7 @@ func FreeAddrInfoW(addrinfo *AddrinfoW) {
func GetIfEntry(pIfRow *MibIfRow) (errcode error) {
r0, _, _ := syscall.Syscall(procGetIfEntry.Addr(), 1, uintptr(unsafe.Pointer(pIfRow)), 0, 0)
if r0 != 0 {
errcode = Errno(r0)
errcode = syscall.Errno(r0)
}
return
}
......@@ -1659,7 +1659,7 @@ func GetIfEntry(pIfRow *MibIfRow) (errcode error) {
func GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode error) {
r0, _, _ := syscall.Syscall(procGetAdaptersInfo.Addr(), 2, uintptr(unsafe.Pointer(ai)), uintptr(unsafe.Pointer(ol)), 0)
if r0 != 0 {
errcode = Errno(r0)
errcode = syscall.Errno(r0)
}
return
}
......@@ -1716,7 +1716,7 @@ func GetUserNameEx(nameFormat uint32, nameBuffre *uint16, nSize *uint32) (err er
func NetUserGetInfo(serverName *uint16, userName *uint16, level uint32, buf **byte) (neterr error) {
r0, _, _ := syscall.Syscall6(procNetUserGetInfo.Addr(), 4, uintptr(unsafe.Pointer(serverName)), uintptr(unsafe.Pointer(userName)), uintptr(level), uintptr(unsafe.Pointer(buf)), 0, 0)
if r0 != 0 {
neterr = Errno(r0)
neterr = syscall.Errno(r0)
}
return
}
......@@ -1724,7 +1724,7 @@ func NetUserGetInfo(serverName *uint16, userName *uint16, level uint32, buf **by
func NetGetJoinInformation(server *uint16, name **uint16, bufType *uint32) (neterr error) {
r0, _, _ := syscall.Syscall(procNetGetJoinInformation.Addr(), 3, uintptr(unsafe.Pointer(server)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(bufType)))
if r0 != 0 {
neterr = Errno(r0)
neterr = syscall.Errno(r0)
}
return
}
......@@ -1732,7 +1732,7 @@ func NetGetJoinInformation(server *uint16, name **uint16, bufType *uint32) (nete
func NetApiBufferFree(buf *byte) (neterr error) {
r0, _, _ := syscall.Syscall(procNetApiBufferFree.Addr(), 1, uintptr(unsafe.Pointer(buf)), 0, 0)
if r0 != 0 {
neterr = Errno(r0)
neterr = syscall.Errno(r0)
}
return
}
......
......@@ -6,27 +6,27 @@ package windows
const (
// Windows errors.
ERROR_FILE_NOT_FOUND Errno = 2
ERROR_PATH_NOT_FOUND Errno = 3
ERROR_ACCESS_DENIED Errno = 5
ERROR_NO_MORE_FILES Errno = 18
ERROR_HANDLE_EOF Errno = 38
ERROR_NETNAME_DELETED Errno = 64
ERROR_FILE_EXISTS Errno = 80
ERROR_BROKEN_PIPE Errno = 109
ERROR_BUFFER_OVERFLOW Errno = 111
ERROR_INSUFFICIENT_BUFFER Errno = 122
ERROR_MOD_NOT_FOUND Errno = 126
ERROR_PROC_NOT_FOUND Errno = 127
ERROR_ALREADY_EXISTS Errno = 183
ERROR_ENVVAR_NOT_FOUND Errno = 203
ERROR_MORE_DATA Errno = 234
ERROR_OPERATION_ABORTED Errno = 995
ERROR_IO_PENDING Errno = 997
ERROR_NOT_FOUND Errno = 1168
ERROR_PRIVILEGE_NOT_HELD Errno = 1314
WSAEACCES Errno = 10013
WSAECONNRESET Errno = 10054
ERROR_FILE_NOT_FOUND syscall.Errno = 2
ERROR_PATH_NOT_FOUND syscall.Errno = 3
ERROR_ACCESS_DENIED syscall.Errno = 5
ERROR_NO_MORE_FILES syscall.Errno = 18
ERROR_HANDLE_EOF syscall.Errno = 38
ERROR_NETNAME_DELETED syscall.Errno = 64
ERROR_FILE_EXISTS syscall.Errno = 80
ERROR_BROKEN_PIPE syscall.Errno = 109
ERROR_BUFFER_OVERFLOW syscall.Errno = 111
ERROR_INSUFFICIENT_BUFFER syscall.Errno = 122
ERROR_MOD_NOT_FOUND syscall.Errno = 126
ERROR_PROC_NOT_FOUND syscall.Errno = 127
ERROR_ALREADY_EXISTS syscall.Errno = 183
ERROR_ENVVAR_NOT_FOUND syscall.Errno = 203
ERROR_MORE_DATA syscall.Errno = 234
ERROR_OPERATION_ABORTED syscall.Errno = 995
ERROR_IO_PENDING syscall.Errno = 997
ERROR_NOT_FOUND syscall.Errno = 1168
ERROR_PRIVILEGE_NOT_HELD syscall.Errno = 1314
WSAEACCES syscall.Errno = 10013
WSAECONNRESET syscall.Errno = 10054
)
const (
......
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