Skip to content

Commit 7562e05

Browse files
committed
Chore: fix a lot code smell
1 parent bf17f2b commit 7562e05

23 files changed

+88
-50
lines changed

src/detection/battery/battery_nbsd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const char* ffDetectBattery(FF_MAYBE_UNUSED FFBatteryOptions* options, FFlist* r
9292
else if (dischargeRate)
9393
{
9494
ffStrbufAppendS(&battery->status, "Discharging, ");
95-
battery->timeRemaining = (int32_t)((double)curr / dischargeRate * 3600)
95+
battery->timeRemaining = (int32_t)((double)curr / dischargeRate * 3600);
9696
}
9797
if (critical)
9898
ffStrbufAppendS(&battery->status, "Critical, ");

src/detection/bios/bios_bsd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const char* ffDetectBios(FFBiosResult* result)
2525
{
2626
ffStrbufSetStatic(&result->type,
2727
ffPathExists("/dev/efi" /*efidev*/, FF_PATHTYPE_FILE) ||
28-
ffPathExists("/boot/efi/efi/" /*efi partition*/, FF_PATHTYPE_DIRECTORY)
28+
ffPathExists("/boot/efi/efi/" /*efi partition. Note /boot/efi exists on BIOS system*/, FF_PATHTYPE_DIRECTORY)
2929
? "UEFI" : "BIOS");
3030
}
3131
}

src/detection/bios/bios_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <stdlib.h>
66

7-
const char *ffDetectBios(FFBiosResult *bios)
7+
const char* ffDetectBios(FFBiosResult* bios)
88
{
99
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/bios_date", "/sys/class/dmi/id/bios_date", &bios->date);
1010
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/bios_release", "/sys/class/dmi/id/bios_release", &bios->release);

src/detection/bios/bios_windows.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,9 @@ const char* ffDetectBios(FFBiosResult* bios)
9494
default: break;
9595
}
9696
}
97-
#elif __HAIKU__
98-
// Currently SMBIOS detection is supported in legency BIOS only
97+
#elif __HAIKU__ || __OpenBSD__
98+
// Currently SMBIOS detection is supported in legancy BIOS only
9999
ffStrbufSetStatic(&bios->type, "BIOS");
100-
#elif __OpenBSD__
101-
FF_AUTO_CLOSE_FD int fd = open("/dev/efi", O_RDONLY);
102-
ffStrbufSetStatic(&bios->type, fd >= 0 ? "UEFI" : "BIOS");
103100
#endif
104101

105102
return NULL;

src/detection/bluetooth/bluetooth_bsd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ const char* ffDetectBluetooth(FF_MAYBE_UNUSED FFBluetoothOptions* options, FF_MA
2121
if (bt_devenum((void*) enumDev, devices) < 0)
2222
return "bt_devenum() failed";
2323

24-
return 0;
24+
return NULL;
2525
}

src/detection/bluetoothradio/bluetoothradio_apple.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
#import <IOBluetooth/IOBluetooth.h>
55

6-
// For some reason the official declaration of IOBluetoothHostController don't include property `controllers`
6+
// For some reason the official declaration of IOBluetoothHostController doesn't include property `controllers`
77
@interface IOBluetoothHostController()
88
+ (id)controllers;
99
@end
1010

11-
const char* ffDetectBluetoothRadio(FFlist* devices /* FFBluetoothResult */)
11+
const char* ffDetectBluetoothRadio(FFlist* devices /* FFBluetoothRadioResult */)
1212
{
1313
NSArray<IOBluetoothHostController*>* ctrls = IOBluetoothHostController.controllers;
1414
if(!ctrls)

src/detection/bluetoothradio/bluetoothradio_windows.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const char* ffDetectBluetoothRadio(FFlist* devices /* FFBluetoothRadioResult */)
8383
ffStrbufInitS(&device->name, blri.localInfo.name);
8484

8585
BLUETOOTH_ADDRESS_STRUCT addr = { .ullLong = blri.localInfo.address };
86-
ffStrbufInitF(&device->address, "%02x:%02x:%02x:%02x:%02x:%02x",
86+
ffStrbufInitF(&device->address, "%02X:%02X:%02X:%02X:%02X:%02X",
8787
addr.rgBytes[5],
8888
addr.rgBytes[4],
8989
addr.rgBytes[3],
@@ -97,6 +97,8 @@ const char* ffDetectBluetoothRadio(FFlist* devices /* FFBluetoothRadioResult */)
9797
device->enabled = true;
9898
device->connectable = ffBluetoothIsConnectable(hRadio);
9999
device->discoverable = ffBluetoothIsDiscoverable(hRadio);
100+
101+
CloseHandle(hRadio);
100102
} while (ffBluetoothFindNextRadio(hFind, &hRadio));
101103

102104
ffBluetoothFindRadioClose(hFind);

src/detection/bootmgr/bootmgr_windows.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#include "bootmgr.h"
22
#include "efi_helper.h"
3+
#include "common/io/io.h"
34

45
#include <windows.h>
56

67
const char* enablePrivilege(const wchar_t* privilege)
78
{
8-
HANDLE token;
9+
FF_AUTO_CLOSE_FD HANDLE token = NULL;
910
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token))
1011
return "OpenProcessToken() failed";
1112

src/detection/brightness/brightness_obsd.c

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,35 @@
88

99
const char* ffDetectBrightness(FF_MAYBE_UNUSED FFBrightnessOptions* options, FFlist* result)
1010
{
11-
FF_AUTO_CLOSE_FD int devfd = open("/dev/ttyC0", O_RDONLY);
12-
13-
if (devfd < 0) return "open(dev/ttyC0, O_RDONLY) failed";
14-
15-
struct wsdisplay_param param = {
16-
.param = WSDISPLAYIO_PARAM_BRIGHTNESS,
17-
};
18-
19-
if (ioctl(devfd, WSDISPLAYIO_GETPARAM, &param) < 0)
20-
return "ioctl(WSDISPLAYIO_GETPARAM) failed";
21-
22-
FFBrightnessResult* brightness = (FFBrightnessResult*) ffListAdd(result);
23-
ffStrbufInitStatic(&brightness->name, "wsdisplay");
24-
25-
brightness->max = param.max;
26-
brightness->min = param.min;
27-
brightness->current = param.curval;
28-
brightness->builtin = true;
11+
char path[] = "/dev/ttyCX";
12+
for (char i = '0'; i <= '9'; ++i) {
13+
path[strlen("/dev/ttyC")] = i;
14+
15+
FF_AUTO_CLOSE_FD int devfd = open(path, O_RDONLY);
16+
17+
if (devfd < 0) {
18+
if (errno == EACCES && i == '0')
19+
return "Permission denied when opening tty device";
20+
if (errno == ENOENT)
21+
break;
22+
continue;
23+
}
24+
25+
struct wsdisplay_param param = {
26+
.param = WSDISPLAYIO_PARAM_BRIGHTNESS,
27+
};
28+
29+
if (ioctl(devfd, WSDISPLAYIO_GETPARAM, &param) < 0)
30+
continue;
31+
32+
FFBrightnessResult* brightness = (FFBrightnessResult*) ffListAdd(result);
33+
ffStrbufInitF(&brightness->name, "ttyC%c", i);
34+
35+
brightness->max = param.max;
36+
brightness->min = param.min;
37+
brightness->current = param.curval;
38+
brightness->builtin = true;
39+
}
2940

3041
return NULL;
3142
}

src/detection/brightness/brightness_windows.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static const char* detectWithDdcci(const FFDisplayServerResult* displayServer, F
4343
FF_LIBRARY_LOAD(dxva2, "dlopen dxva2" FF_LIBRARY_EXTENSION " failed", "dxva2" FF_LIBRARY_EXTENSION, 1)
4444
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(dxva2, GetPhysicalMonitorsFromHMONITOR)
4545
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(dxva2, GetMonitorBrightness)
46+
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(dxva2, DestroyPhysicalMonitor)
4647

4748
FF_LIST_FOR_EACH(FFDisplayResult, display, displayServer->displays)
4849
{
@@ -64,6 +65,8 @@ static const char* detectWithDdcci(const FFDisplayServerResult* displayServer, F
6465
brightness->current = curr;
6566
brightness->builtin = false;
6667
}
68+
69+
ffDestroyPhysicalMonitor(physicalMonitor.hPhysicalMonitor);
6770
}
6871
}
6972
return NULL;

0 commit comments

Comments
 (0)