mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-09 06:30:10 +01:00
Chore: introduce macro ARRAY_SIZE
This commit is contained in:
@@ -76,7 +76,7 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
|
||||
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD)
|
||||
{
|
||||
char query[32];
|
||||
snprintf(query, sizeof(query), "%X,\t%X,", (unsigned) pc->pc_device, (unsigned) pc->pc_revid);
|
||||
snprintf(query, ARRAY_SIZE(query), "%X,\t%X,", (unsigned) pc->pc_device, (unsigned) pc->pc_revid);
|
||||
ffParsePropFileData("libdrm/amdgpu.ids", query, &gpu->name);
|
||||
}
|
||||
if (gpu->name.length == 0)
|
||||
|
||||
@@ -128,7 +128,7 @@ const char* ffDetectIntelGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverRe
|
||||
if (result.memory)
|
||||
{
|
||||
ctl_mem_handle_t memoryModules[16];
|
||||
uint32_t memoryCount = sizeof(memoryModules) / sizeof(memoryModules[0]);
|
||||
uint32_t memoryCount = ARRAY_SIZE(memoryModules);
|
||||
if (igclData.ffctlEnumMemoryModules(device, &memoryCount, memoryModules) == CTL_RESULT_SUCCESS && memoryCount > 0)
|
||||
{
|
||||
result.memory->used = 0;
|
||||
@@ -157,7 +157,7 @@ const char* ffDetectIntelGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverRe
|
||||
if (result.temp)
|
||||
{
|
||||
ctl_temp_handle_t sensors[16];
|
||||
uint32_t sensorCount = sizeof(sensors) / sizeof(sensors[0]);
|
||||
uint32_t sensorCount = ARRAY_SIZE(sensors);
|
||||
if (igclData.ffctlEnumTemperatureSensors(device, &sensorCount, sensors) == CTL_RESULT_SUCCESS && sensorCount > 0)
|
||||
{
|
||||
double sumValue = 0;
|
||||
@@ -178,7 +178,7 @@ const char* ffDetectIntelGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverRe
|
||||
if (result.frequency)
|
||||
{
|
||||
ctl_freq_handle_t domains[16];
|
||||
uint32_t domainCount = sizeof(domains) / sizeof(domains[0]);
|
||||
uint32_t domainCount = ARRAY_SIZE(domains);
|
||||
if (igclData.ffctlEnumFrequencyDomains(device, &domainCount, domains) == CTL_RESULT_SUCCESS && domainCount > 0)
|
||||
{
|
||||
double maxValue = 0;
|
||||
|
||||
@@ -32,7 +32,7 @@ static bool pciDetectDriver(FFstrbuf* result, FFstrbuf* pciDir, FFstrbuf* buffer
|
||||
uint32_t pciDirLength = pciDir->length;
|
||||
ffStrbufAppendS(pciDir, "/driver");
|
||||
char pathBuf[PATH_MAX];
|
||||
ssize_t resultLength = readlink(pciDir->chars, pathBuf, sizeof(pathBuf));
|
||||
ssize_t resultLength = readlink(pciDir->chars, pathBuf, ARRAY_SIZE(pathBuf));
|
||||
if(resultLength <= 0) return false;
|
||||
|
||||
const char* slash = memrchr(pathBuf, '/', (size_t) resultLength);
|
||||
@@ -415,7 +415,7 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf
|
||||
const char* pPciPath = NULL;
|
||||
if (drmKey)
|
||||
{
|
||||
ssize_t pathLength = readlink(deviceDir->chars, pciPath, sizeof(pciPath) - 1);
|
||||
ssize_t pathLength = readlink(deviceDir->chars, pciPath, ARRAY_SIZE(pciPath) - 1);
|
||||
if (pathLength <= 0)
|
||||
return "Unable to get PCI device path";
|
||||
pciPath[pathLength] = '\0';
|
||||
@@ -460,7 +460,7 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf
|
||||
{
|
||||
if (ffStrStartsWith(entry->d_name, "card"))
|
||||
{
|
||||
ffStrCopyN(drmKeyBuffer, entry->d_name, sizeof(drmKeyBuffer));
|
||||
ffStrCopyN(drmKeyBuffer, entry->d_name, ARRAY_SIZE(drmKeyBuffer));
|
||||
drmKey = drmKeyBuffer;
|
||||
break;
|
||||
}
|
||||
@@ -493,7 +493,7 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf
|
||||
if (pend != buffer->chars)
|
||||
{
|
||||
char query[32];
|
||||
snprintf(query, sizeof(query), "%X,\t%X,", (unsigned) deviceId, (unsigned) revision);
|
||||
snprintf(query, ARRAY_SIZE(query), "%X,\t%X,", (unsigned) deviceId, (unsigned) revision);
|
||||
#ifdef FF_CUSTOM_AMDGPU_IDS_PATH
|
||||
ffParsePropFile(FF_STR(FF_CUSTOM_AMDGPU_IDS_PATH), query, &gpu->name);
|
||||
#else
|
||||
|
||||
@@ -86,7 +86,7 @@ const char *ffDetectMthreadsGpuInfo(const FFGpuDriverCondition *cond, FFGpuDrive
|
||||
if (cond->type & FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID)
|
||||
{
|
||||
char pciBusIdStr[32];
|
||||
snprintf(pciBusIdStr, sizeof(pciBusIdStr) - 1, "%04x:%02x:%02x.%d", cond->pciBusId.domain, cond->pciBusId.bus, cond->pciBusId.device, cond->pciBusId.func);
|
||||
snprintf(pciBusIdStr, ARRAY_SIZE(pciBusIdStr) - 1, "%04x:%02x:%02x.%d", cond->pciBusId.domain, cond->pciBusId.bus, cond->pciBusId.device, cond->pciBusId.func);
|
||||
|
||||
MtmlReturn ret = mtmlData.ffmtmlLibraryInitDeviceByPciSbdf(mtmlData.lib, pciBusIdStr, &device);
|
||||
if (ret != MTML_SUCCESS)
|
||||
@@ -195,7 +195,7 @@ const char *ffDetectMthreadsGpuInfo(const FFGpuDriverCondition *cond, FFGpuDrive
|
||||
if (result.name)
|
||||
{
|
||||
char name[MTML_DEVICE_NAME_BUFFER_SIZE];
|
||||
if (mtmlData.ffmtmlDeviceGetName(device, name, sizeof(name)) == MTML_SUCCESS)
|
||||
if (mtmlData.ffmtmlDeviceGetName(device, name, ARRAY_SIZE(name)) == MTML_SUCCESS)
|
||||
ffStrbufSetS(result.name, name);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverR
|
||||
if (cond->type & FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID)
|
||||
{
|
||||
char pciBusIdStr[32];
|
||||
snprintf(pciBusIdStr, sizeof(pciBusIdStr) - 1, "%04x:%02x:%02x.%d", cond->pciBusId.domain, cond->pciBusId.bus, cond->pciBusId.device, cond->pciBusId.func);
|
||||
snprintf(pciBusIdStr, ARRAY_SIZE(pciBusIdStr) - 1, "%04x:%02x:%02x.%d", cond->pciBusId.domain, cond->pciBusId.bus, cond->pciBusId.device, cond->pciBusId.func);
|
||||
|
||||
nvmlReturn_t ret = nvmlData.ffnvmlDeviceGetHandleByPciBusId_v2(pciBusIdStr, &device);
|
||||
if (ret != NVML_SUCCESS)
|
||||
@@ -148,7 +148,7 @@ const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverR
|
||||
if (result.name)
|
||||
{
|
||||
char name[NVML_DEVICE_NAME_V2_BUFFER_SIZE];
|
||||
if (nvmlData.ffnvmlDeviceGetName(device, name, sizeof(name)) == NVML_SUCCESS)
|
||||
if (nvmlData.ffnvmlDeviceGetName(device, name, ARRAY_SIZE(name)) == NVML_SUCCESS)
|
||||
ffStrbufSetS(result.name, name);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ static void parsePciIdsFile(const FFstrbuf* content, uint8_t subclass, uint16_t
|
||||
char buffer[32];
|
||||
|
||||
// Search for vendor
|
||||
uint32_t len = (uint32_t) snprintf(buffer, sizeof(buffer), "\n%04x ", vendor);
|
||||
uint32_t len = (uint32_t) snprintf(buffer, ARRAY_SIZE(buffer), "\n%04x ", vendor);
|
||||
char* start = (char*) memmem(content->chars, content->length, buffer, len);
|
||||
char* end = content->chars + content->length;
|
||||
if (start)
|
||||
@@ -83,7 +83,7 @@ static void parsePciIdsFile(const FFstrbuf* content, uint8_t subclass, uint16_t
|
||||
}
|
||||
|
||||
// Search for device
|
||||
len = (uint32_t) snprintf(buffer, sizeof(buffer), "\n\t%04x ", device);
|
||||
len = (uint32_t) snprintf(buffer, ARRAY_SIZE(buffer), "\n\t%04x ", device);
|
||||
start = memmem(start, (size_t) (end - start), buffer, len);
|
||||
if (start)
|
||||
{
|
||||
@@ -138,7 +138,7 @@ static bool loadPciidsInc(uint8_t subclass, uint16_t vendor, uint16_t device, FF
|
||||
if (!gpu->vendor.length)
|
||||
ffStrbufSetS(&gpu->vendor, pvendor->name);
|
||||
|
||||
const FFPciDevice* pdevice = (const FFPciDevice*) bsearch(&device, pvendor->devices, pvendor->nDevices, sizeof(FFPciDevice), (void*) pciDeviceCmp);
|
||||
const FFPciDevice* pdevice = (const FFPciDevice*) bsearch(&device, pvendor->devices, pvendor->nDevices, sizeof(*pdevice), (void*) pciDeviceCmp);
|
||||
|
||||
if (pdevice)
|
||||
{
|
||||
|
||||
@@ -67,7 +67,7 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
|
||||
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD)
|
||||
{
|
||||
char query[32];
|
||||
snprintf(query, sizeof(query), "%X,\t%X,", (unsigned) deviceId, (unsigned) revision);
|
||||
snprintf(query, ARRAY_SIZE(query), "%X,\t%X,", (unsigned) deviceId, (unsigned) revision);
|
||||
ffParsePropFileData("libdrm/amdgpu.ids", query, &gpu->name);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user