Global: replaces NULL to nullptr

This commit is contained in:
李通洲
2026-07-10 18:08:04 +08:00
parent 873454191f
commit ba18705d2e
387 changed files with 2411 additions and 2411 deletions
+9 -9
View File
@@ -17,11 +17,11 @@ static inline void wrapYyjsonFree(yyjson_doc** doc) {
static const char* parseTermuxApi(FFBatteryOptions* options, FFlist* results) {
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
if (ffProcessAppendStdOut(&buffer, (char* const[]) { FF_TERMUX_API_PATH, FF_TERMUX_API_PARAM, NULL })) {
if (ffProcessAppendStdOut(&buffer, (char* const[]) { FF_TERMUX_API_PATH, FF_TERMUX_API_PARAM, nullptr })) {
return "Starting `" FF_TERMUX_API_PATH " " FF_TERMUX_API_PARAM "` failed";
}
yyjson_doc* FF_A_CLEANUP(wrapYyjsonFree) doc = yyjson_read_opts(buffer.chars, buffer.length, 0, NULL, NULL);
yyjson_doc* FF_A_CLEANUP(wrapYyjsonFree) doc = yyjson_read_opts(buffer.chars, buffer.length, 0, nullptr, nullptr);
if (!doc) {
return "Failed to parse battery info";
}
@@ -66,7 +66,7 @@ static const char* parseTermuxApi(FFBatteryOptions* options, FFlist* results) {
battery->temperature = yyjson_get_num(yyjson_obj_get(root, "temperature"));
}
return NULL;
return nullptr;
}
static const char* parseDumpsys(FFBatteryOptions* options, FFlist* results) {
@@ -74,8 +74,8 @@ static const char* parseDumpsys(FFBatteryOptions* options, FFlist* results) {
if (ffProcessAppendStdOut(&buf, (char*[]) {
"/system/bin/dumpsys",
"battery",
NULL,
}) != NULL ||
nullptr,
}) != nullptr ||
buf.length == 0) {
return "Executing `/system/bin/dumpsys battery` failed"; // Only works in `adb shell`, or when rooted
}
@@ -88,7 +88,7 @@ static const char* parseDumpsys(FFBatteryOptions* options, FFlist* results) {
FF_STRBUF_AUTO_DESTROY temp = ffStrbufCreate();
if (!ffParsePropLines(start, "present: ", &temp) || !ffStrbufEqualS(&temp, "true")) {
return NULL;
return nullptr;
}
ffStrbufClear(&temp);
@@ -148,13 +148,13 @@ static const char* parseDumpsys(FFBatteryOptions* options, FFlist* results) {
ffParsePropLines(start, "technology: ", &battery->technology);
return NULL;
return nullptr;
}
const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) {
const char* error = parseTermuxApi(options, results);
if (error && parseDumpsys(options, results) == NULL) {
return NULL;
if (error && parseDumpsys(options, results) == nullptr) {
return nullptr;
}
return error;
}
+10 -10
View File
@@ -15,18 +15,18 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) {
io_registry_entry_t registryEntry;
while ((registryEntry = IOIteratorNext(iterator)) != IO_OBJECT_NULL) {
FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryBattery = registryEntry;
FF_CFTYPE_AUTO_RELEASE CFMutableDictionaryRef properties = NULL;
FF_CFTYPE_AUTO_RELEASE CFMutableDictionaryRef properties = nullptr;
if (IORegistryEntryCreateCFProperties(entryBattery, &properties, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess) {
continue;
}
int currentCapacity, maxCapacity;
if (ffCfDictGetInt(properties, CFSTR(kIOPMPSMaxCapacityKey), &maxCapacity) != NULL || maxCapacity <= 0) {
if (ffCfDictGetInt(properties, CFSTR(kIOPMPSMaxCapacityKey), &maxCapacity) != nullptr || maxCapacity <= 0) {
continue;
}
if (ffCfDictGetInt(properties, CFSTR(kIOPMPSCurrentCapacityKey), &currentCapacity) != NULL || currentCapacity <= 0) {
if (ffCfDictGetInt(properties, CFSTR(kIOPMPSCurrentCapacityKey), &currentCapacity) != nullptr || currentCapacity <= 0) {
continue;
}
@@ -63,7 +63,7 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) {
battery->cycleCount = cycleCount < 0 ? 0 : (uint32_t) cycleCount;
battery->timeRemaining = -1;
if (ffCfDictGetBool(properties, CFSTR(kIOPMPSExternalConnectedKey), &boolValue) == NULL) {
if (ffCfDictGetBool(properties, CFSTR(kIOPMPSExternalConnectedKey), &boolValue) == nullptr) {
if (boolValue) {
battery->status |= FF_BATTERY_STATUS_AC_CONNECTED;
} else {
@@ -76,24 +76,24 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) {
}
}
}
if (ffCfDictGetBool(properties, CFSTR(kIOPMPSIsChargingKey), &boolValue) == NULL && boolValue) {
if (ffCfDictGetBool(properties, CFSTR(kIOPMPSIsChargingKey), &boolValue) == nullptr && boolValue) {
battery->status |= FF_BATTERY_STATUS_CHARGING;
}
if (ffCfDictGetBool(properties, CFSTR(kIOPMPSAtCriticalLevelKey), &boolValue) == NULL && boolValue) {
if (ffCfDictGetBool(properties, CFSTR(kIOPMPSAtCriticalLevelKey), &boolValue) == nullptr && boolValue) {
battery->status |= FF_BATTERY_STATUS_CRITICAL;
}
int sbdsManufactureDate = 0;
if (ffCfDictGetInt(properties, CFSTR(kIOPMPSManufactureDateKey), &sbdsManufactureDate) == NULL) {
if (ffCfDictGetInt(properties, CFSTR(kIOPMPSManufactureDateKey), &sbdsManufactureDate) == nullptr) {
int day = sbdsManufactureDate & 0b11111;
int month = (sbdsManufactureDate >> 5) & 0b1111;
int year = (sbdsManufactureDate >> 9) + 1800;
ffStrbufSetF(&battery->manufactureDate, "%.4d-%.2d-%.2d", year, month, day);
} else {
CFDictionaryRef batteryData;
if (ffCfDictGetDict(properties, CFSTR("BatteryData"), &batteryData) == NULL) {
if (ffCfDictGetDict(properties, CFSTR("BatteryData"), &batteryData) == nullptr) {
char manufactureDate[sizeof(uint64_t)];
if (ffCfDictGetInt64(batteryData, CFSTR(kIOPMPSManufactureDateKey), (int64_t*) manufactureDate) == NULL) {
if (ffCfDictGetInt64(batteryData, CFSTR(kIOPMPSManufactureDateKey), (int64_t*) manufactureDate) == nullptr) {
// https://github.com/AsahiLinux/linux/blob/b5c05cbffb0488c7618106926d522cc3b43d93d5/drivers/power/supply/macsmc_power.c#L410-L419
int year = (manufactureDate[0] - '0') * 10 + (manufactureDate[1] - '0') + 2000 - 8;
int month = (manufactureDate[2] - '0') * 10 + (manufactureDate[3] - '0');
@@ -113,5 +113,5 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) {
}
}
return NULL;
return nullptr;
}
+2 -2
View File
@@ -18,7 +18,7 @@ const char* ffDetectBattery(FF_A_UNUSED FFBatteryOptions* options, FFlist* resul
}
if (units == 0) {
return NULL;
return nullptr;
}
FF_AUTO_CLOSE_FD int acpifd = open("/dev/acpi", O_RDONLY | O_CLOEXEC);
@@ -86,5 +86,5 @@ const char* ffDetectBattery(FF_A_UNUSED FFBatteryOptions* options, FFlist* resul
}
#endif
}
return NULL;
return nullptr;
}
+2 -2
View File
@@ -50,7 +50,7 @@ const char* parseBattery(int dfd, const char* battId, FFlist* results) {
battery->status |= FF_BATTERY_STATUS_AC_CONNECTED;
}
return NULL;
return nullptr;
}
const char* ffDetectBattery(FF_A_UNUSED FFBatteryOptions* options, FFlist* results) {
@@ -67,5 +67,5 @@ const char* ffDetectBattery(FF_A_UNUSED FFBatteryOptions* options, FFlist* resul
parseBattery(dirfd(dir), entry->d_name, results);
}
return NULL;
return nullptr;
}
+4 -4
View File
@@ -175,14 +175,14 @@ static bool parseBattery(int dfd, const char* id, FFBatteryOptions* options, FFl
const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) {
FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/class/power_supply/");
if (dirp == NULL) {
return "opendir(\"/sys/class/power_supply/\") == NULL";
if (dirp == nullptr) {
return "opendir(\"/sys/class/power_supply/\") == nullptr";
}
bool acConnected = false;
struct dirent* entry;
while ((entry = readdir(dirp)) != NULL) {
while ((entry = readdir(dirp)) != nullptr) {
if (entry->d_name[0] == '.') {
continue;
}
@@ -199,5 +199,5 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) {
}
}
return NULL;
return nullptr;
}
+6 -6
View File
@@ -20,7 +20,7 @@ const char* ffDetectBattery(FF_A_UNUSED FFBatteryOptions* options, FFlist* resul
return "open(_PATH_SYSMON, O_RDONLY | O_CLOEXEC) failed";
}
prop_dictionary_t root = NULL;
prop_dictionary_t root = nullptr;
if (prop_dictionary_recv_ioctl(fd, ENVSYS_GETDICTIONARY, &root) < 0) {
return "prop_dictionary_recv_ioctl(ENVSYS_GETDICTIONARY) failed";
}
@@ -35,7 +35,7 @@ const char* ffDetectBattery(FF_A_UNUSED FFBatteryOptions* options, FFlist* resul
}
prop_object_iterator_t itKey = prop_dictionary_iterator(root);
for (prop_dictionary_keysym_t key; (key = prop_object_iterator_next(itKey)) != NULL;) {
for (prop_dictionary_keysym_t key; (key = prop_object_iterator_next(itKey)) != nullptr;) {
if (!ffStrStartsWith(prop_dictionary_keysym_value(key), "acpibat")) {
continue;
}
@@ -44,12 +44,12 @@ const char* ffDetectBattery(FF_A_UNUSED FFBatteryOptions* options, FFlist* resul
uint32_t max = 0, curr = 0, dischargeRate = 0;
bool charging = false, critical = false;
prop_object_iterator_t iter = prop_array_iterator(bat);
for (prop_dictionary_t dict; (dict = prop_object_iterator_next(iter)) != NULL;) {
for (prop_dictionary_t dict; (dict = prop_object_iterator_next(iter)) != nullptr;) {
if (prop_object_type(dict) != PROP_TYPE_DICTIONARY) {
continue;
}
const char* desc = NULL;
const char* desc = nullptr;
if (!prop_dictionary_get_string(dict, "description", &desc)) {
continue;
}
@@ -64,7 +64,7 @@ const char* ffDetectBattery(FF_A_UNUSED FFBatteryOptions* options, FFlist* resul
} else if (ffStrEquals(desc, "charge")) {
prop_dictionary_get_uint32(dict, "max-value", &max);
prop_dictionary_get_uint32(dict, "cur-value", &curr);
const char* state = NULL;
const char* state = nullptr;
if (prop_dictionary_get_string(dict, "state", &state) && ffStrEquals(state, "critical")) {
critical = true;
}
@@ -105,5 +105,5 @@ const char* ffDetectBattery(FF_A_UNUSED FFBatteryOptions* options, FFlist* resul
prop_object_iterator_release(itKey);
prop_object_release(root);
return NULL;
return nullptr;
}
+2 -2
View File
@@ -20,7 +20,7 @@ const char* ffDetectBattery(FF_A_UNUSED FFBatteryOptions* options, FFlist* resul
}
if (info.battery_state == APM_BATTERY_ABSENT) {
return NULL;
return nullptr;
}
FFBatteryResult* battery = FF_LIST_ADD(FFBatteryResult, *result);
@@ -56,5 +56,5 @@ const char* ffDetectBattery(FF_A_UNUSED FFBatteryOptions* options, FFlist* resul
}
}
return NULL;
return nullptr;
}
+22 -22
View File
@@ -51,21 +51,21 @@ static FFBatteryWmiEntry* getBatteryEntry(FFlist* entries, FFlist* results, ULON
}
static const char* queryWmiAllData(const GUID* guid, const char* guidStr, PWNODE_ALL_DATA* pAllData, ULONG* pBufferSize) {
FF_AUTO_CLOSE_WMI_BLOCK HANDLE hBlock = NULL;
FF_AUTO_CLOSE_WMI_BLOCK HANDLE hBlock = nullptr;
ULONG status = WmiOpenBlock(guid, WMIGUID_QUERY, &hBlock);
if (status != ERROR_SUCCESS) {
FF_DEBUG("WMI: WmiOpenBlock() failed for %s: %s", guidStr, ffDebugWin32Error(status));
return "WmiOpenBlock() failed";
}
status = WmiQueryAllDataW(hBlock, pBufferSize, NULL);
status = WmiQueryAllDataW(hBlock, pBufferSize, nullptr);
if (status != ERROR_SUCCESS && status != ERROR_INSUFFICIENT_BUFFER) {
FF_DEBUG("WMI: first WmiQueryAllDataW() failed: %s", ffDebugWin32Error(status));
return "WmiQueryAllDataW(NULL) failed";
return "WmiQueryAllDataW(nullptr) failed";
}
if (*pBufferSize == 0) {
return "WmiQueryAllDataW(NULL) returned no data";
return "WmiQueryAllDataW(nullptr) returned no data";
}
if (*pBufferSize < sizeof(WNODE_ALL_DATA)) {
@@ -79,11 +79,11 @@ static const char* queryWmiAllData(const GUID* guid, const char* guidStr, PWNODE
if (status != ERROR_SUCCESS) {
FF_DEBUG("WMI: second WmiQueryAllDataW failed: %s", ffDebugWin32Error(status));
free(*pAllData);
*pAllData = NULL;
*pAllData = nullptr;
return "WmiQueryAllDataW(*pAllData) failed";
}
return NULL;
return nullptr;
}
static bool getInstanceData(const PWNODE_ALL_DATA allData, ULONG bufferSize, ULONG index, const uint8_t** instanceData, ULONG* instanceLength) {
@@ -109,7 +109,7 @@ static bool getInstanceData(const PWNODE_ALL_DATA allData, ULONG bufferSize, ULO
static void detectStaticData(FFlist* entries, FFlist* results) {
FF_DEBUG("detectStaticData");
FF_AUTO_FREE PWNODE_ALL_DATA allData = NULL;
FF_AUTO_FREE PWNODE_ALL_DATA allData = nullptr;
ULONG bufferSize = 0;
const char* error = queryWmiAllData(&BATTERY_STATIC_DATA_WMI_GUID, "BATTERY_STATIC_DATA_WMI_GUID", &allData, &bufferSize);
if (error) {
@@ -117,7 +117,7 @@ static void detectStaticData(FFlist* entries, FFlist* results) {
}
for (ULONG i = 0; i < allData->InstanceCount; ++i) {
const uint8_t* instanceData = NULL;
const uint8_t* instanceData = nullptr;
ULONG instanceLength = 0;
if (!getInstanceData(allData, bufferSize, i, &instanceData, &instanceLength) || instanceLength < offsetof(BATTERY_WMI_STATIC_DATA, Strings)) {
continue;
@@ -187,7 +187,7 @@ static void detectStaticData(FFlist* entries, FFlist* results) {
static void detectStatus(FFlist* entries, FFlist* results) {
FF_DEBUG("detectStatus");
FF_AUTO_FREE PWNODE_ALL_DATA allData = NULL;
FF_AUTO_FREE PWNODE_ALL_DATA allData = nullptr;
ULONG bufferSize = 0;
const char* error = queryWmiAllData(&BATTERY_STATUS_WMI_GUID, "BATTERY_STATUS_WMI_GUID", &allData, &bufferSize);
if (error) {
@@ -195,7 +195,7 @@ static void detectStatus(FFlist* entries, FFlist* results) {
}
for (ULONG i = 0; i < allData->InstanceCount; ++i) {
const uint8_t* instanceData = NULL;
const uint8_t* instanceData = nullptr;
ULONG instanceLength = 0;
if (!getInstanceData(allData, bufferSize, i, &instanceData, &instanceLength) || instanceLength < sizeof(BATTERY_WMI_STATUS)) {
continue;
@@ -225,7 +225,7 @@ static void detectStatus(FFlist* entries, FFlist* results) {
static void detectRuntime(FFlist* entries, FFlist* results) {
FF_DEBUG("detectRuntime");
FF_AUTO_FREE PWNODE_ALL_DATA allData = NULL;
FF_AUTO_FREE PWNODE_ALL_DATA allData = nullptr;
ULONG bufferSize = 0;
const char* error = queryWmiAllData(&BATTERY_RUNTIME_WMI_GUID, "BATTERY_RUNTIME_WMI_GUID", &allData, &bufferSize);
if (error) {
@@ -233,7 +233,7 @@ static void detectRuntime(FFlist* entries, FFlist* results) {
}
for (ULONG i = 0; i < allData->InstanceCount; ++i) {
const uint8_t* instanceData = NULL;
const uint8_t* instanceData = nullptr;
ULONG instanceLength = 0;
if (!getInstanceData(allData, bufferSize, i, &instanceData, &instanceLength) || instanceLength < sizeof(BATTERY_WMI_RUNTIME)) {
continue;
@@ -249,7 +249,7 @@ static void detectRuntime(FFlist* entries, FFlist* results) {
static void detectFullChargedCapacity(FFlist* entries, FFlist* results) {
FF_DEBUG("detectFullChargedCapacity");
FF_AUTO_FREE PWNODE_ALL_DATA allData = NULL;
FF_AUTO_FREE PWNODE_ALL_DATA allData = nullptr;
ULONG bufferSize = 0;
const char* error = queryWmiAllData(&BATTERY_FULL_CHARGED_CAPACITY_WMI_GUID, "BATTERY_FULL_CHARGED_CAPACITY_WMI_GUID", &allData, &bufferSize);
if (error) {
@@ -257,7 +257,7 @@ static void detectFullChargedCapacity(FFlist* entries, FFlist* results) {
}
for (ULONG i = 0; i < allData->InstanceCount; ++i) {
const uint8_t* instanceData = NULL;
const uint8_t* instanceData = nullptr;
ULONG instanceLength = 0;
if (!getInstanceData(allData, bufferSize, i, &instanceData, &instanceLength) || instanceLength < sizeof(BATTERY_WMI_FULL_CHARGED_CAPACITY)) {
continue;
@@ -275,7 +275,7 @@ static void detectFullChargedCapacity(FFlist* entries, FFlist* results) {
static void detectCycleCount(FFlist* entries, FFlist* results) {
FF_DEBUG("detectCycleCount");
FF_AUTO_FREE PWNODE_ALL_DATA allData = NULL;
FF_AUTO_FREE PWNODE_ALL_DATA allData = nullptr;
ULONG bufferSize = 0;
const char* error = queryWmiAllData(&BATTERY_CYCLE_COUNT_WMI_GUID, "BATTERY_CYCLE_COUNT_WMI_GUID", &allData, &bufferSize);
if (error) {
@@ -283,7 +283,7 @@ static void detectCycleCount(FFlist* entries, FFlist* results) {
}
for (ULONG i = 0; i < allData->InstanceCount; ++i) {
const uint8_t* instanceData = NULL;
const uint8_t* instanceData = nullptr;
ULONG instanceLength = 0;
if (!getInstanceData(allData, bufferSize, i, &instanceData, &instanceLength) || instanceLength < sizeof(BATTERY_WMI_CYCLE_COUNT)) {
continue;
@@ -296,7 +296,7 @@ static void detectCycleCount(FFlist* entries, FFlist* results) {
static void detectTemperature(FFlist* entries, FFlist* results) {
FF_DEBUG("detectTemperature");
FF_AUTO_FREE PWNODE_ALL_DATA allData = NULL;
FF_AUTO_FREE PWNODE_ALL_DATA allData = nullptr;
ULONG bufferSize = 0;
const char* error = queryWmiAllData(&BATTERY_TEMPERATURE_WMI_GUID, "BATTERY_TEMPERATURE_WMI_GUID", &allData, &bufferSize);
if (error) {
@@ -304,7 +304,7 @@ static void detectTemperature(FFlist* entries, FFlist* results) {
}
for (ULONG i = 0; i < allData->InstanceCount; ++i) {
const uint8_t* instanceData = NULL;
const uint8_t* instanceData = nullptr;
ULONG instanceLength = 0;
if (!getInstanceData(allData, bufferSize, i, &instanceData, &instanceLength) || instanceLength < sizeof(BATTERY_WMI_TEMPERATURE)) {
continue;
@@ -319,7 +319,7 @@ static const char* detectWithNtApi(FFBatteryResult* battery) {
// Reports summary battery information, not per battery
FF_DEBUG("NtApi: start detection");
SYSTEM_BATTERY_STATE info;
NTSTATUS status = NtPowerInformation(SystemBatteryState, NULL, 0, &info, sizeof(info));
NTSTATUS status = NtPowerInformation(SystemBatteryState, nullptr, 0, &info, sizeof(info));
if (!NT_SUCCESS(status)) {
FF_DEBUG("NtApi: NtPowerInformation(SystemBatteryState) failed: %s", ffDebugNtStatus(status));
return "NtPowerInformation(SystemBatteryState) failed";
@@ -346,7 +346,7 @@ static const char* detectWithNtApi(FFBatteryResult* battery) {
battery->status |= FF_BATTERY_STATUS_CRITICAL;
}
battery->timeRemaining = info.EstimatedTime == BATTERY_UNKNOWN_TIME ? -1 : (int32_t) info.EstimatedTime;
return NULL;
return nullptr;
}
const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) {
@@ -355,7 +355,7 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) {
FF_LIST_AUTO_DESTROY entries = ffListCreate();
detectStaticData(&entries, results);
if (results->length == 0) {
return NULL;
return nullptr;
} else if (results->length == 1) {
// Fast path for single battery
detectWithNtApi(FF_LIST_FIRST(FFBatteryWmiEntry, entries)->result);
@@ -380,5 +380,5 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) {
}
FF_DEBUG("WMI: finished detection, total results=%u", results->length);
return NULL;
return nullptr;
}