windows: errnoErr(): return ENOENT to reduce code duplication

Change-Id: I51c08a4add9c2b31c4bb7c4421dde227b4fff489
GitHub-Last-Rev: ef8ef8646c
GitHub-Pull-Request: golang/sys#89
Reviewed-on: https://go-review.googlesource.com/c/sys/+/259537
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Alex Brainman <alex.brainman@gmail.com>
This commit is contained in:
Sebastiaan van Stijn
2020-10-09 00:24:30 +00:00
committed by Ian Lance Taylor
parent c1f3e3309c
commit dfb3f7c4e6
3 changed files with 255 additions and 1263 deletions

View File

@@ -303,17 +303,13 @@ func (r *Rets) SetReturnValuesCode() string {
func (r *Rets) useLongHandleErrorCode(retvar string) string {
const code = `if %s {
if e1 != 0 {
err = errnoErr(e1)
} else {
err = %sEINVAL
}
err = errnoErr(e1)
}`
cond := retvar + " == 0"
if r.FailCond != "" {
cond = strings.Replace(r.FailCond, "failretval", retvar, 1)
}
return fmt.Sprintf(code, cond, syscalldot())
return fmt.Sprintf(code, cond)
}
// SetErrorCode returns source code that sets return parameters.
@@ -867,7 +863,7 @@ var (
func errnoErr(e {{syscalldot}}Errno) error {
switch e {
case 0:
return nil
return {{syscalldot}}EINVAL
case errnoERROR_IO_PENDING:
return errERROR_IO_PENDING
}

View File

@@ -390,11 +390,7 @@ func GetProcAddressByOrdinal(module Handle, ordinal uintptr) (proc uintptr, err
r0, _, e1 := syscall.Syscall(procGetProcAddress.Addr(), 2, uintptr(module), ordinal, 0)
proc = uintptr(r0)
if proc == 0 {
if e1 != 0 {
err = errnoErr(e1)
} else {
err = syscall.EINVAL
}
err = errnoErr(e1)
}
return
}
@@ -1091,11 +1087,7 @@ func WSASendMsg(fd Handle, msg *WSAMsg, flags uint32, bytesSent *uint32, overlap
}
r1, _, e1 := syscall.Syscall6(sendRecvMsgFunc.sendAddr, 6, uintptr(fd), uintptr(unsafe.Pointer(msg)), uintptr(flags), uintptr(unsafe.Pointer(bytesSent)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)))
if r1 == socket_error {
if e1 != 0 {
err = errnoErr(e1)
} else {
err = syscall.EINVAL
}
err = errnoErr(e1)
}
return err
}
@@ -1107,11 +1099,7 @@ func WSARecvMsg(fd Handle, msg *WSAMsg, bytesReceived *uint32, overlapped *Overl
}
r1, _, e1 := syscall.Syscall6(sendRecvMsgFunc.recvAddr, 5, uintptr(fd), uintptr(unsafe.Pointer(msg)), uintptr(unsafe.Pointer(bytesReceived)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)), 0)
if r1 == socket_error {
if e1 != 0 {
err = errnoErr(e1)
} else {
err = syscall.EINVAL
}
err = errnoErr(e1)
}
return err
}

File diff suppressed because it is too large Load Diff