1
0
mirror of https://git.zx2c4.com/wireguard-go synced 2024-11-15 01:05:15 +01:00

Simplify SetupDiEnumDeviceInfo() synopsis

The SetupDiEnumDeviceInfo() now returns a SP_DEVINFO_DATA rather than
taking it on input to fill it on return.

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2019-02-04 11:40:44 +01:00 committed by Jason A. Donenfeld
parent 20f1512b7c
commit 38c7acd70f
2 changed files with 10 additions and 11 deletions

View File

@ -122,9 +122,11 @@ func SetupDiGetDeviceInfoListDetail(DeviceInfoSet DevInfo) (data *DevInfoListDet
} }
// SetupDiEnumDeviceInfo function returns a SP_DEVINFO_DATA structure that specifies a device information element in a device information set. // SetupDiEnumDeviceInfo function returns a SP_DEVINFO_DATA structure that specifies a device information element in a device information set.
func SetupDiEnumDeviceInfo(DeviceInfoSet DevInfo, MemberIndex int, data *SP_DEVINFO_DATA) error { func SetupDiEnumDeviceInfo(DeviceInfoSet DevInfo, MemberIndex int) (DeviceInfoData *SP_DEVINFO_DATA, err error) {
data.Size = uint32(unsafe.Sizeof(*data)) data := SP_DEVINFO_DATA{}
return setupDiEnumDeviceInfo(DeviceInfoSet, uint32(MemberIndex), data) data.Size = uint32(unsafe.Sizeof(data))
return &data, setupDiEnumDeviceInfo(DeviceInfoSet, uint32(MemberIndex), &data)
} }
// SetupDiOpenDevRegKey function opens a registry key for device-specific configuration information. // SetupDiOpenDevRegKey function opens a registry key for device-specific configuration information.

View File

@ -146,9 +146,8 @@ func TestSetupDiEnumDeviceInfo(t *testing.T) {
} }
defer devInfoList.Close() defer devInfoList.Close()
var data SP_DEVINFO_DATA
for i := 0; true; i++ { for i := 0; true; i++ {
err := SetupDiEnumDeviceInfo(devInfoList, i, &data) data, err := SetupDiEnumDeviceInfo(devInfoList, i)
if err != nil { if err != nil {
if errWin, ok := err.(syscall.Errno); ok && errWin == 259 /*ERROR_NO_MORE_ITEMS*/ { if errWin, ok := err.(syscall.Errno); ok && errWin == 259 /*ERROR_NO_MORE_ITEMS*/ {
break break
@ -169,9 +168,8 @@ func TestSetupDiOpenDevRegKey(t *testing.T) {
} }
defer devInfoList.Close() defer devInfoList.Close()
var data SP_DEVINFO_DATA
for i := 0; true; i++ { for i := 0; true; i++ {
err := SetupDiEnumDeviceInfo(devInfoList, i, &data) data, err := SetupDiEnumDeviceInfo(devInfoList, i)
if err != nil { if err != nil {
if errWin, ok := err.(syscall.Errno); ok && errWin == 259 /*ERROR_NO_MORE_ITEMS*/ { if errWin, ok := err.(syscall.Errno); ok && errWin == 259 /*ERROR_NO_MORE_ITEMS*/ {
break break
@ -179,7 +177,7 @@ func TestSetupDiOpenDevRegKey(t *testing.T) {
continue continue
} }
key, err := SetupDiOpenDevRegKey(devInfoList, &data, DICS_FLAG_GLOBAL, 0, DIREG_DRV, windows.KEY_READ) key, err := SetupDiOpenDevRegKey(devInfoList, data, DICS_FLAG_GLOBAL, 0, DIREG_DRV, windows.KEY_READ)
if err != nil { if err != nil {
t.Errorf("Error calling SetupDiOpenDevRegKey: %s", err.Error()) t.Errorf("Error calling SetupDiOpenDevRegKey: %s", err.Error())
} }
@ -194,9 +192,8 @@ func TestSetupDiGetDeviceInstallParams(t *testing.T) {
} }
defer devInfoList.Close() defer devInfoList.Close()
var data SP_DEVINFO_DATA
for i := 0; true; i++ { for i := 0; true; i++ {
err := SetupDiEnumDeviceInfo(devInfoList, i, &data) data, err := SetupDiEnumDeviceInfo(devInfoList, i)
if err != nil { if err != nil {
if errWin, ok := err.(syscall.Errno); ok && errWin == 259 /*ERROR_NO_MORE_ITEMS*/ { if errWin, ok := err.(syscall.Errno); ok && errWin == 259 /*ERROR_NO_MORE_ITEMS*/ {
break break
@ -204,7 +201,7 @@ func TestSetupDiGetDeviceInstallParams(t *testing.T) {
continue continue
} }
_, err = SetupDiGetDeviceInstallParams(devInfoList, &data) _, err = SetupDiGetDeviceInstallParams(devInfoList, data)
if err != nil { if err != nil {
t.Errorf("Error calling SetupDiOpenDevRegKey: %s", err.Error()) t.Errorf("Error calling SetupDiOpenDevRegKey: %s", err.Error())
} }