windnsapi: Fix incorrect error checking

This commit is contained in:
世界 2024-08-19 17:37:13 +08:00
parent 96bef0733f
commit afd8993773
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
4 changed files with 21 additions and 5 deletions

View file

@ -0,0 +1,16 @@
package windnsapi
import (
"runtime"
"testing"
"github.com/stretchr/testify/require"
)
func TestDNSAPI(t *testing.T) {
if runtime.GOOS != "windows" {
t.SkipNow()
}
t.Parallel()
require.NoError(t, FlushResolverCache())
}

View file

@ -3,4 +3,4 @@ package windnsapi
//go:generate go run golang.org/x/sys/windows/mkwinsyscall -output zsyscall_windows.go syscall_windows.go
// dnsapi.DnsFlushResolverCache is an undocumented function
//sys FlushResolverCache() (ret error) = dnsapi.DnsFlushResolverCache
//sys FlushResolverCache() (err error) = dnsapi.DnsFlushResolverCache

View file

@ -43,10 +43,10 @@ var (
procDnsFlushResolverCache = moddnsapi.NewProc("DnsFlushResolverCache")
)
func FlushResolverCache() (ret error) {
r0, _, _ := syscall.Syscall(procDnsFlushResolverCache.Addr(), 0, 0, 0, 0)
if r0 != 0 {
ret = syscall.Errno(r0)
func FlushResolverCache() (err error) {
r1, _, e1 := syscall.Syscall(procDnsFlushResolverCache.Addr(), 0, 0, 0, 0)
if r1 == 0 {
err = errnoErr(e1)
}
return
}