From 5fb1286e155c315e5523decfad75d1d9e65af678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 4 May 2024 12:11:42 +0800 Subject: [PATCH] Battery (Windows): simplify code --- src/detection/battery/battery_windows.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/detection/battery/battery_windows.c b/src/detection/battery/battery_windows.c index d0fec9557..357000ec3 100644 --- a/src/detection/battery/battery_windows.c +++ b/src/detection/battery/battery_windows.c @@ -1,4 +1,6 @@ #include "battery.h" + +#include "common/io/io.h" #include "util/windows/unicode.h" #include "util/mallocHelper.h" #include "util/smbiosHelper.h" @@ -20,11 +22,6 @@ NtPowerInformation( OUT PVOID OutputBuffer OPTIONAL, IN ULONG OutputBufferLength); -static inline void wrapCloseHandle(HANDLE* handle) -{ - if(*handle) - CloseHandle(*handle); -} static inline void wrapSetupDiDestroyDeviceInfoList(HDEVINFO* hdev) { if(*hdev) @@ -52,7 +49,7 @@ static const char* detectWithSetupApi(FFBatteryOptions* options, FFlist* results if(!SetupDiGetDeviceInterfaceDetailW(hdev, &did, pdidd, cbRequired, &cbRequired, NULL)) continue; - HANDLE __attribute__((__cleanup__(wrapCloseHandle))) hBattery = + HANDLE FF_AUTO_CLOSE_FD hBattery = CreateFileW(pdidd->DevicePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if(hBattery == INVALID_HANDLE_VALUE)