mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 17:41:41 +01:00
Chore: introduce macro ARRAY_SIZE
This commit is contained in:
+1
-1
@@ -43,6 +43,6 @@ typedef struct FFformatarg
|
||||
void ffFormatAppendFormatArg(FFstrbuf* buffer, const FFformatarg* formatarg);
|
||||
void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t numArgs, const FFformatarg* arguments);
|
||||
#define FF_PARSE_FORMAT_STRING_CHECKED(buffer, formatstr, numArgs, arguments) do {\
|
||||
static_assert(sizeof(arguments) / sizeof(*(arguments)) == (numArgs), "Invalid number of format arguments");\
|
||||
static_assert(sizeof(arguments) / sizeof(*arguments) == (numArgs), "Invalid number of format arguments");\
|
||||
ffParseFormatString((buffer), (formatstr), (numArgs), (arguments));\
|
||||
} while (0)
|
||||
|
||||
@@ -14,7 +14,7 @@ typedef enum FFPrintType {
|
||||
void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType);
|
||||
void ffPrintFormat(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType, uint32_t numArgs, const FFformatarg* arguments);
|
||||
#define FF_PRINT_FORMAT_CHECKED(moduleName, moduleIndex, moduleArgs, printType, numArgs, arguments) do {\
|
||||
static_assert(sizeof(arguments) / sizeof(*(arguments)) == (numArgs), "Invalid number of format arguments");\
|
||||
static_assert(sizeof(arguments) / sizeof(*arguments) == (numArgs), "Invalid number of format arguments");\
|
||||
ffPrintFormat((moduleName), (moduleIndex), (moduleArgs), (printType), (numArgs), (arguments));\
|
||||
} while (0)
|
||||
FF_C_PRINTF(5, 6) void ffPrintError(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType, const char* message, ...);
|
||||
@@ -23,6 +23,6 @@ void ffPrintCharTimes(char c, uint32_t times);
|
||||
|
||||
void ffPrintModuleFormatHelp(const char* name, const char* def, uint32_t numArgs, const char* args[]);
|
||||
#define FF_PRINT_MODULE_FORMAT_HELP_CHECKED(moduleName, def, numArgs, args) do {\
|
||||
static_assert(sizeof(args) / sizeof(*(args)) == (numArgs), "Invalid number of format arguments");\
|
||||
static_assert(sizeof(args) / sizeof(*args) == (numArgs), "Invalid number of format arguments");\
|
||||
ffPrintModuleFormatHelp((moduleName), (def), (numArgs), (args));\
|
||||
} while (0)
|
||||
|
||||
@@ -153,14 +153,14 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
|
||||
|
||||
size_t len = 0;
|
||||
int mibs[] = { CTL_KERN, KERN_PROCARGS2, pid };
|
||||
if (sysctl(mibs, sizeof(mibs) / sizeof(*mibs), NULL, &len, NULL, 0) == 0)
|
||||
if (sysctl(mibs, ARRAY_SIZE(mibs), NULL, &len, NULL, 0) == 0)
|
||||
{// try get arg0
|
||||
#ifndef MAC_OS_X_VERSION_10_15
|
||||
//don't know why if don't let len longer, proArgs2 and len will change during the following sysctl() in old MacOS version.
|
||||
len++;
|
||||
#endif
|
||||
FF_AUTO_FREE char* const procArgs2 = malloc(len);
|
||||
if (sysctl(mibs, sizeof(mibs) / sizeof(*mibs), procArgs2, &len, NULL, 0) == 0)
|
||||
if (sysctl(mibs, ARRAY_SIZE(mibs), procArgs2, &len, NULL, 0) == 0)
|
||||
{
|
||||
// https://gist.github.com/nonowarn/770696#file-getargv-c-L46
|
||||
uint32_t argc = *(uint32_t*) procArgs2;
|
||||
|
||||
@@ -50,7 +50,7 @@ const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool use
|
||||
int timeout = instance.config.general.processingTimeout;
|
||||
|
||||
wchar_t pipeName[32];
|
||||
swprintf(pipeName, sizeof(pipeName) / sizeof(*pipeName), L"\\\\.\\pipe\\FASTFETCH-%u", GetCurrentProcessId());
|
||||
swprintf(pipeName, ARRAY_SIZE(pipeName), L"\\\\.\\pipe\\FASTFETCH-%u", GetCurrentProcessId());
|
||||
|
||||
FF_AUTO_CLOSE_FD HANDLE hChildPipeRead = CreateNamedPipeW(
|
||||
pipeName,
|
||||
|
||||
@@ -100,7 +100,7 @@ bool ffParsePropFileValues(const char* filename, uint32_t numQueries, FFpropquer
|
||||
bool valueStorage[32];
|
||||
bool* unsetValues = valueStorage;
|
||||
|
||||
if (numQueries > sizeof(valueStorage) / sizeof(valueStorage[0]))
|
||||
if (numQueries > ARRAY_SIZE(valueStorage))
|
||||
unsetValues = malloc(sizeof(bool) * numQueries);
|
||||
|
||||
bool allSet = true;
|
||||
|
||||
@@ -38,9 +38,9 @@ const char* ffDetectBootmgr(FFBootmgrResult* result)
|
||||
|
||||
uint8_t buffer[2048];
|
||||
wchar_t key[16];
|
||||
swprintf(key, sizeof(key) / sizeof(*key), L"Boot%04X", value);
|
||||
swprintf(key, ARRAY_SIZE(key), L"Boot%04X", value);
|
||||
uint32_t size = GetFirmwareEnvironmentVariableW(key, L"{" FF_EFI_GLOBAL_GUID L"}", buffer, sizeof(buffer));
|
||||
if (size < sizeof(FFEfiLoadOption) || size == sizeof(buffer))
|
||||
if (size < sizeof(FFEfiLoadOption) || size == ARRAY_SIZE(buffer))
|
||||
return "GetFirmwareEnvironmentVariableW(Boot####) failed";
|
||||
|
||||
ffEfiFillLoadOption((FFEfiLoadOption *)buffer, result);
|
||||
|
||||
@@ -92,13 +92,13 @@ static const char* detectWithDdcci(FF_MAYBE_UNUSED const FFDisplayServerResult*
|
||||
|
||||
for (uint32_t i = 0; i < 2; ++i)
|
||||
{
|
||||
IOAVServiceWriteI2C(service, 0x37, 0x51, i2cIn, sizeof(i2cIn));
|
||||
IOAVServiceWriteI2C(service, 0x37, 0x51, i2cIn, ARRAY_SIZE(i2cIn));
|
||||
usleep(options->ddcciSleep * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t i2cOut[12] = {};
|
||||
if (IOAVServiceReadI2C(service, 0x37, 0x51, i2cOut, sizeof(i2cOut)) == KERN_SUCCESS)
|
||||
if (IOAVServiceReadI2C(service, 0x37, 0x51, i2cOut, ARRAY_SIZE(i2cOut)) == KERN_SUCCESS)
|
||||
{
|
||||
if (i2cOut[2] != 0x02 || i2cOut[3] != 0x00)
|
||||
continue;
|
||||
@@ -113,7 +113,7 @@ static const char* detectWithDdcci(FF_MAYBE_UNUSED const FFDisplayServerResult*
|
||||
ffStrbufInit(&brightness->name);
|
||||
|
||||
uint8_t edid[128] = {};
|
||||
if (IOAVServiceReadI2C(service, 0x50, 0x00, edid, sizeof(edid)) == KERN_SUCCESS)
|
||||
if (IOAVServiceReadI2C(service, 0x50, 0x00, edid, ARRAY_SIZE(edid)) == KERN_SUCCESS)
|
||||
ffEdidGetName(edid, &brightness->name);
|
||||
}
|
||||
}
|
||||
@@ -155,12 +155,12 @@ static const char* detectWithDdcci(const FFDisplayServerResult* displayServer, F
|
||||
.sendAddress = 0x6e,
|
||||
.sendTransactionType = kIOI2CSimpleTransactionType,
|
||||
.sendBuffer = (vm_address_t) i2cIn,
|
||||
.sendBytes = sizeof(i2cIn) / sizeof(i2cIn[0]),
|
||||
.sendBytes = ARRAY_SIZE(i2cIn),
|
||||
.minReplyDelay = options->ddcciSleep,
|
||||
.replyAddress = 0x6F,
|
||||
.replySubAddress = 0x51,
|
||||
.replyTransactionType = kIOI2CDDCciReplyTransactionType,
|
||||
.replyBytes = sizeof(i2cOut) / sizeof(i2cOut[0]),
|
||||
.replyBytes = ARRAY_SIZE(i2cOut),
|
||||
.replyBuffer = (vm_address_t) i2cOut,
|
||||
};
|
||||
IOReturn ret = IOI2CSendRequest(connect, kNilOptions, &request);
|
||||
|
||||
@@ -16,7 +16,7 @@ const char* ffDetectBrightness(FF_MAYBE_UNUSED FFBrightnessOptions* options, FFl
|
||||
|
||||
for (char i = '0'; i <= '9'; ++i)
|
||||
{
|
||||
path[sizeof(path) - 2] = i;
|
||||
path[ARRAY_SIZE(path) - 2] = i;
|
||||
|
||||
FF_AUTO_CLOSE_FD int blfd = open(path, O_RDONLY | O_CLOEXEC);
|
||||
if (blfd < 0)
|
||||
|
||||
@@ -48,7 +48,7 @@ static const char* detectWithBacklight(FFlist* result)
|
||||
// if we managed to get edid, use it
|
||||
ffStrbufAppendS(&brightness->name, "/edid");
|
||||
uint8_t edidData[128];
|
||||
if(ffReadFileData(brightness->name.chars, sizeof(edidData), edidData) == sizeof(edidData))
|
||||
if(ffReadFileData(brightness->name.chars, ARRAY_SIZE(edidData), edidData) == ARRAY_SIZE(edidData))
|
||||
{
|
||||
ffStrbufClear(&brightness->name);
|
||||
ffEdidGetName(edidData, &brightness->name);
|
||||
|
||||
@@ -24,8 +24,8 @@ static const char* enumerateDevices(FFBtrfsResult* item, int dfd, FFstrbuf* buff
|
||||
ffStrbufAppendC(&item->devices, ',');
|
||||
ffStrbufAppendS(&item->devices, entry->d_name);
|
||||
|
||||
char path[sizeof(entry->d_name) + sizeof("/size") + 1];
|
||||
snprintf(path, sizeof(path), "%s/size", entry->d_name);
|
||||
char path[ARRAY_SIZE(entry->d_name) + ARRAY_SIZE("/size") + 1];
|
||||
snprintf(path, ARRAY_SIZE(path), "%s/size", entry->d_name);
|
||||
|
||||
if (ffReadFileBufferRelative(subfd, path, buffer))
|
||||
item->totalSize += ffStrbufToUInt(buffer, 0) * 512;
|
||||
|
||||
@@ -16,7 +16,7 @@ const char* ffDetectCamera(FFlist* result)
|
||||
|
||||
for (uint32_t i = 0; i <= 9; ++i)
|
||||
{
|
||||
path[sizeof(path) - 2] = (char) (i + '0');
|
||||
path[ARRAY_SIZE(path) - 2] = (char) (i + '0');
|
||||
FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY);
|
||||
if (fd < 0)
|
||||
break;
|
||||
|
||||
@@ -52,7 +52,7 @@ const char* ffDetectCamera(FF_MAYBE_UNUSED FFlist* result)
|
||||
|
||||
wchar_t buffer[256];
|
||||
uint32_t length = 0;
|
||||
if (FAILED(device->GetString(MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME, buffer, sizeof(buffer), &length)) || length == 0)
|
||||
if (FAILED(device->GetString(MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME, buffer, ARRAY_SIZE(buffer), &length)) || length == 0)
|
||||
continue;
|
||||
|
||||
FFCameraResult* camera = (FFCameraResult*) ffListAdd(result);
|
||||
@@ -63,7 +63,7 @@ const char* ffDetectCamera(FF_MAYBE_UNUSED FFlist* result)
|
||||
camera->width = 0;
|
||||
camera->height = 0;
|
||||
|
||||
if (SUCCEEDED(device->GetString(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, buffer, sizeof(buffer), &length)) && length > 0)
|
||||
if (SUCCEEDED(device->GetString(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, buffer, ARRAY_SIZE(buffer), &length)) && length > 0)
|
||||
ffStrbufSetNWS(&camera->id, length, buffer);
|
||||
|
||||
IMFMediaSource* FF_AUTO_RELEASE_COM_OBJECT source = nullptr;
|
||||
|
||||
@@ -13,7 +13,7 @@ const char* ffDetectCPU(const FFCPUOptions* options, FFCPUResult* cpu)
|
||||
" 2-Core", " 4-Core", " 6-Core", " 8-Core", " 10-Core", " 12-Core", " 14-Core", " 16-Core",
|
||||
" with Radeon Graphics"
|
||||
};
|
||||
ffStrbufRemoveStrings(&cpu->name, sizeof(removeStrings) / sizeof(removeStrings[0]), removeStrings);
|
||||
ffStrbufRemoveStrings(&cpu->name, ARRAY_SIZE(removeStrings), removeStrings);
|
||||
ffStrbufSubstrBeforeFirstC(&cpu->name, '@'); //Cut the speed output in the name as we append our own
|
||||
ffStrbufTrimRight(&cpu->name, ' '); //If we removed the @ in previous step there was most likely a space before it
|
||||
return NULL;
|
||||
|
||||
@@ -85,8 +85,8 @@ static const char* detectCoreCount(FFCPUResult* cpu)
|
||||
if (nPerfLevels <= 0) return "sysctl(hw.nperflevels) failed";
|
||||
|
||||
char sysctlKey[] = "hw.perflevelN.logicalcpu";
|
||||
if (nPerfLevels > sizeof(cpu->coreTypes) / sizeof(cpu->coreTypes[0]))
|
||||
nPerfLevels = sizeof(cpu->coreTypes) / sizeof(cpu->coreTypes[0]);
|
||||
if (nPerfLevels > ARRAY_SIZE(cpu->coreTypes))
|
||||
nPerfLevels = ARRAY_SIZE(cpu->coreTypes);
|
||||
for (uint32_t i = 0; i < nPerfLevels; ++i)
|
||||
{
|
||||
sysctlKey[strlen("hw.perflevel")] = (char) ('0' + i);
|
||||
|
||||
@@ -389,7 +389,7 @@ FF_MAYBE_UNUSED static void detectArmSoc(FFCPUResult* cpu)
|
||||
|
||||
// device-vendor,device-model\0soc-vendor,soc-model\0
|
||||
char content[256];
|
||||
ssize_t length = ffReadFileData("/proc/device-tree/compatible", sizeof(content), content);
|
||||
ssize_t length = ffReadFileData("/proc/device-tree/compatible", ARRAY_SIZE(content), content);
|
||||
if (length <= 2) return;
|
||||
|
||||
// get the second NUL terminated string if it exists
|
||||
|
||||
@@ -14,7 +14,7 @@ const char* ffDetectCPUCache(FFCPUCacheResult* result)
|
||||
char sysctlKey[128] = "hw.perflevelN.";
|
||||
char* pNum = sysctlKey + strlen("hw.perflevel");
|
||||
char* pSubkey = sysctlKey + strlen("hw.perflevelN.");
|
||||
const size_t lenLeft = sizeof(sysctlKey) - strlen("hw.perflevelN.");
|
||||
const size_t lenLeft = ARRAY_SIZE(sysctlKey) - strlen("hw.perflevelN.");
|
||||
|
||||
for (uint32_t i = 0; i < nPerfLevels; ++i)
|
||||
{
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
const char* ffGetCpuUsageInfo(FFlist* cpuTimes)
|
||||
{
|
||||
char buf[PROC_FILE_BUFFSIZ];
|
||||
ssize_t nRead = ffReadFileData("/proc/stat", sizeof(buf) - 1, buf);
|
||||
ssize_t nRead = ffReadFileData("/proc/stat", ARRAY_SIZE(buf) - 1, buf);
|
||||
if(nRead < 0)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
return "Accessing \"/proc/stat\" is restricted on Android O+";
|
||||
#else
|
||||
return "ffReadFileData(\"/proc/stat\", sizeof(buf) - 1, buf) failed";
|
||||
return "ffReadFileData(\"/proc/stat\", ARRAY_SIZE(buf) - 1, buf) failed";
|
||||
#endif
|
||||
}
|
||||
buf[nRead] = '\0';
|
||||
|
||||
@@ -204,7 +204,7 @@ static bool isRemovable(FFDisk* currentDisk)
|
||||
return false;
|
||||
|
||||
char sysBlockPartition[64];
|
||||
snprintf(sysBlockPartition, sizeof(sysBlockPartition), "/sys/class/block/%s", currentDisk->mountFrom.chars + strlen("/dev/"));
|
||||
snprintf(sysBlockPartition, ARRAY_SIZE(sysBlockPartition), "/sys/class/block/%s", currentDisk->mountFrom.chars + strlen("/dev/"));
|
||||
|
||||
char sysBlockVolume[PATH_MAX]; // /sys/devices/pci0000:00/0000:00:14.0/usb4/4-3/4-3:1.0/host0/target0:0:0/0:0:0:0/block/sda/sda1
|
||||
if (realpath(sysBlockPartition, sysBlockVolume) == NULL)
|
||||
@@ -235,7 +235,7 @@ static void detectStats(FFDisk* disk)
|
||||
{
|
||||
struct statvfs fs;
|
||||
if(statvfs(disk->mountpoint.chars, &fs) != 0)
|
||||
memset(&fs, 0, sizeof(struct statvfs)); //Set all values to 0, so our values get initialized to 0 too
|
||||
memset(&fs, 0, sizeof(fs)); //Set all values to 0, so our values get initialized to 0 too
|
||||
|
||||
disk->bytesTotal = fs.f_blocks * fs.f_frsize;
|
||||
disk->bytesFree = fs.f_bfree * fs.f_frsize;
|
||||
|
||||
@@ -86,7 +86,7 @@ static void detectStats(FFDisk* disk)
|
||||
{
|
||||
struct statvfs fs;
|
||||
if(statvfs(disk->mountpoint.chars, &fs) != 0)
|
||||
memset(&fs, 0, sizeof(struct statvfs));
|
||||
memset(&fs, 0, sizeof(fs));
|
||||
|
||||
disk->bytesTotal = fs.f_blocks * fs.f_frsize;
|
||||
disk->bytesFree = fs.f_bfree * fs.f_frsize;
|
||||
|
||||
@@ -22,9 +22,9 @@ static unsigned __stdcall testRemoteVolumeAccessible(void* mountpoint)
|
||||
const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
|
||||
{
|
||||
wchar_t buf[MAX_PATH + 1];
|
||||
uint32_t length = GetLogicalDriveStringsW(sizeof(buf) / sizeof(*buf), buf);
|
||||
if (length == 0 || length >= sizeof(buf) / sizeof(*buf))
|
||||
return "GetLogicalDriveStringsW(sizeof(buf) / sizeof(*buf), buf) failed";
|
||||
uint32_t length = GetLogicalDriveStringsW(ARRAY_SIZE(buf), buf);
|
||||
if (length == 0 || length >= ARRAY_SIZE(buf))
|
||||
return "GetLogicalDriveStringsW(ARRAY_SIZE(buf), buf) failed";
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
|
||||
|
||||
@@ -32,7 +32,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
|
||||
if (__builtin_expect(options->folders.length == 1 && options->folders.chars[0] == '/', 0))
|
||||
{
|
||||
wchar_t path[MAX_PATH + 1];
|
||||
GetSystemWindowsDirectoryW(path, sizeof(path) / sizeof(*path));
|
||||
GetSystemWindowsDirectoryW(path, ARRAY_SIZE(path));
|
||||
ffStrbufSetF(&options->folders, "%c:\\", (char) path[0]);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
|
||||
{
|
||||
wchar_t volumeName[MAX_PATH + 1];
|
||||
mountpoint[2] = L'\0';
|
||||
if(QueryDosDeviceW(mountpoint, volumeName, sizeof(volumeName) / sizeof(*volumeName)))
|
||||
if(QueryDosDeviceW(mountpoint, volumeName, ARRAY_SIZE(volumeName)))
|
||||
ffStrbufSetWS(&disk->mountFrom, volumeName);
|
||||
mountpoint[2] = L'\\';
|
||||
}
|
||||
@@ -104,11 +104,11 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
|
||||
|
||||
DWORD diskFlags;
|
||||
BOOL result = GetVolumeInformationW(mountpoint,
|
||||
diskName, sizeof(diskName) / sizeof(*diskName), //Volume name
|
||||
diskName, ARRAY_SIZE(diskName), //Volume name
|
||||
NULL, //Serial number
|
||||
NULL, //Max component length
|
||||
&diskFlags, //File system flags
|
||||
diskFileSystem, sizeof(diskFileSystem) / sizeof(*diskFileSystem)
|
||||
diskFileSystem, ARRAY_SIZE(diskFileSystem)
|
||||
);
|
||||
SetErrorMode(errorMode);
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ static void parseDiskIOCounters(int dfd, const char* devName, FFlist* result, FF
|
||||
if (!multiNs)
|
||||
{
|
||||
char pathSysBlock[16];
|
||||
snprintf(pathSysBlock, sizeof(pathSysBlock), "nvme%dn2", devid);
|
||||
snprintf(pathSysBlock, ARRAY_SIZE(pathSysBlock), "nvme%dn2", devid);
|
||||
multiNs = faccessat(devfd, pathSysBlock, F_OK, 0) == 0;
|
||||
}
|
||||
if (multiNs)
|
||||
@@ -56,7 +56,7 @@ static void parseDiskIOCounters(int dfd, const char* devName, FFlist* result, FF
|
||||
uint64_t nRead, sectorRead, nWritten, sectorWritten;
|
||||
{
|
||||
char sysBlockStat[PROC_FILE_BUFFSIZ];
|
||||
ssize_t fileSize = ffReadFileDataRelative(dfd, "stat", sizeof(sysBlockStat) - 1, sysBlockStat);
|
||||
ssize_t fileSize = ffReadFileDataRelative(dfd, "stat", ARRAY_SIZE(sysBlockStat) - 1, sysBlockStat);
|
||||
if (fileSize <= 0) return;
|
||||
sysBlockStat[fileSize] = '\0';
|
||||
if (sscanf(sysBlockStat, "%" PRIu64 "%*u%" PRIu64 "%*u%" PRIu64 "%*u%" PRIu64 "%*u", &nRead, §orRead, &nWritten, §orWritten) <= 0)
|
||||
|
||||
@@ -22,7 +22,7 @@ static bool detectPhysicalDisk(const wchar_t* szDevice, FFlist* result, FFDiskIO
|
||||
},
|
||||
sizeof(STORAGE_PROPERTY_QUERY),
|
||||
&sddBuffer,
|
||||
sizeof(sddBuffer),
|
||||
ARRAY_SIZE(sddBuffer),
|
||||
&retSize,
|
||||
NULL
|
||||
) || retSize == 0)
|
||||
|
||||
@@ -21,7 +21,7 @@ static void detectDisplays(FFDisplayServerResult* ds)
|
||||
{
|
||||
CGDirectDisplayID screens[128];
|
||||
uint32_t screenCount;
|
||||
if(CGGetOnlineDisplayList(sizeof(screens) / sizeof(screens[0]), screens, &screenCount) != kCGErrorSuccess)
|
||||
if(CGGetOnlineDisplayList(ARRAY_SIZE(screens), screens, &screenCount) != kCGErrorSuccess)
|
||||
return;
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
|
||||
|
||||
@@ -36,9 +36,9 @@ static void detectDisplays(FFDisplayServerResult* ds)
|
||||
EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, (LPARAM) &monitors);
|
||||
|
||||
DISPLAYCONFIG_PATH_INFO paths[128];
|
||||
uint32_t pathCount = sizeof(paths) / sizeof(paths[0]);
|
||||
uint32_t pathCount = ARRAY_SIZE(paths);
|
||||
DISPLAYCONFIG_MODE_INFO modes[256];
|
||||
uint32_t modeCount = sizeof(modes) / sizeof(modes[0]);
|
||||
uint32_t modeCount = ARRAY_SIZE(modes);
|
||||
|
||||
if (QueryDisplayConfig(
|
||||
QDC_ONLY_ACTIVE_PATHS,
|
||||
@@ -66,7 +66,7 @@ static void detectDisplays(FFDisplayServerResult* ds)
|
||||
{
|
||||
FF_LIST_FOR_EACH(FFMonitorInfo, item, monitors)
|
||||
{
|
||||
if (wcsncmp(item->info.szDevice, sourceName.viewGdiDeviceName, sizeof(sourceName.viewGdiDeviceName) / sizeof(wchar_t)) == 0)
|
||||
if (wcsncmp(item->info.szDevice, sourceName.viewGdiDeviceName, ARRAY_SIZE(sourceName.viewGdiDeviceName)) == 0)
|
||||
{
|
||||
monitorInfo = item;
|
||||
break;
|
||||
@@ -102,11 +102,11 @@ static void detectDisplays(FFDisplayServerResult* ds)
|
||||
*pRegPath = *pDevPath;
|
||||
++pRegPath;
|
||||
++pDevPath;
|
||||
assert(pRegPath < regPath + sizeof(regPath) / sizeof(wchar_t) + strlen("Device Parameters"));
|
||||
assert(pRegPath < regPath + ARRAY_SIZE(regPath) + strlen("Device Parameters"));
|
||||
}
|
||||
wcscpy(pRegPath, L"Device Parameters");
|
||||
|
||||
edidLength = sizeof(edidData);
|
||||
edidLength = ARRAY_SIZE(edidData);
|
||||
if (RegGetValueW(HKEY_LOCAL_MACHINE, regPath, L"EDID", RRF_RT_REG_BINARY, NULL, edidData, &edidLength) == ERROR_SUCCESS &&
|
||||
edidLength > 0 && edidLength % 128 == 0)
|
||||
{
|
||||
|
||||
@@ -58,7 +58,7 @@ static const char* drmParseSysfs(FFDisplayServerResult* result)
|
||||
}
|
||||
|
||||
uint8_t edidData[512];
|
||||
ssize_t edidLength = ffReadFileData(drmDir.chars, sizeof(edidData), edidData);
|
||||
ssize_t edidLength = ffReadFileData(drmDir.chars, ARRAY_SIZE(edidData), edidData);
|
||||
if(edidLength <= 0 || edidLength % 128 != 0)
|
||||
{
|
||||
edidLength = 0;
|
||||
@@ -66,7 +66,7 @@ static const char* drmParseSysfs(FFDisplayServerResult* result)
|
||||
ffStrbufAppendS(&drmDir, "/modes");
|
||||
|
||||
char modes[32];
|
||||
if (ffReadFileData(drmDir.chars, sizeof(modes), modes) >= 3)
|
||||
if (ffReadFileData(drmDir.chars, ARRAY_SIZE(modes), modes) >= 3)
|
||||
{
|
||||
sscanf(modes, "%ux%u", &width, &height);
|
||||
ffStrbufAppendS(&name, plainName);
|
||||
@@ -194,7 +194,7 @@ FF_MAYBE_UNUSED static const char* drmGetEdidByConnId(uint32_t connId, uint8_t*
|
||||
char connectorId[16] = {};
|
||||
|
||||
ffStrbufAppendS(&drmDir, "/connector_id");
|
||||
ffReadFileData(drmDir.chars, sizeof(connectorId), connectorId);
|
||||
ffReadFileData(drmDir.chars, ARRAY_SIZE(connectorId), connectorId);
|
||||
if (strtoul(connectorId, NULL, 10) != connId)
|
||||
{
|
||||
ffStrbufSubstrBefore(&drmDir, drmDirLength);
|
||||
@@ -229,7 +229,7 @@ static const char* drmConnectLibdrm(FFDisplayServerResult* result)
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libdrm, drmFreeDevices)
|
||||
|
||||
drmDevice* devices[64];
|
||||
int nDevices = ffdrmGetDevices(devices, sizeof(devices) / sizeof(devices[0]));
|
||||
int nDevices = ffdrmGetDevices(devices, ARRAY_SIZE(devices));
|
||||
if (nDevices <= 0)
|
||||
return "drmGetDevices() failed";
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
static bool waylandDetectWM(int fd, FFDisplayServerResult* result)
|
||||
{
|
||||
struct ucred ucred;
|
||||
socklen_t len = sizeof(struct ucred);
|
||||
socklen_t len = sizeof(ucred);
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &len) == -1 || ucred.pid <= 0)
|
||||
return false;
|
||||
|
||||
@@ -108,7 +108,7 @@ static bool matchDrmConnector(const char* connName, WaylandDisplay* wldata)
|
||||
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateF("%s%s/edid", drmDirPath, entry->d_name);
|
||||
|
||||
uint8_t edidData[512];
|
||||
ssize_t edidLength = ffReadFileData(path.chars, sizeof(edidData), edidData);
|
||||
ssize_t edidLength = ffReadFileData(path.chars, ARRAY_SIZE(edidData), edidData);
|
||||
if (edidLength > 0 && edidLength % 128 == 0)
|
||||
{
|
||||
ffEdidGetName(edidData, &wldata->edidName);
|
||||
@@ -249,7 +249,7 @@ const char* ffdsConnectWayland(FFDisplayServerResult* result)
|
||||
FF_LIST_FOR_EACH(FFstrbuf, basePath, instance.state.platform.configDirs)
|
||||
{
|
||||
char path[1024];
|
||||
snprintf(path, sizeof(path) - 1, "%s%s", basePath->chars, fileName);
|
||||
snprintf(path, ARRAY_SIZE(path) - 1, "%s%s", basePath->chars, fileName);
|
||||
if (ffReadFileBuffer(path, &monitorsXml))
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -260,11 +260,11 @@ static const char* getFromProcesses(FFDisplayServerResult* result)
|
||||
int request[] = {CTL_KERN, KERN_PROC, KERN_PROC_UID, (int) userId};
|
||||
size_t length = 0;
|
||||
|
||||
if(sysctl(request, sizeof(request) / sizeof(*request), NULL, &length, NULL, 0) != 0)
|
||||
if(sysctl(request, ARRAY_SIZE(request), NULL, &length, NULL, 0) != 0)
|
||||
return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_UID}, NULL) failed";
|
||||
|
||||
FF_AUTO_FREE struct kinfo_proc* procs = (struct kinfo_proc*) malloc(length);
|
||||
if(sysctl(request, sizeof(request) / sizeof(*request), procs, &length, NULL, 0) != 0)
|
||||
if(sysctl(request, ARRAY_SIZE(request), procs, &length, NULL, 0) != 0)
|
||||
return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_UID}, procs) failed";
|
||||
|
||||
length /= sizeof(*procs);
|
||||
@@ -283,7 +283,7 @@ static const char* getFromProcesses(FFDisplayServerResult* result)
|
||||
#elif __OpenBSD__
|
||||
kvm_t* kd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, NULL);
|
||||
int count = 0;
|
||||
const struct kinfo_proc* proc = kvm_getprocs(kd, KERN_PROC_UID, userId, sizeof(struct kinfo_proc), &count);
|
||||
const struct kinfo_proc* proc = kvm_getprocs(kd, KERN_PROC_UID, userId, sizeof(*proc), &count);
|
||||
if (proc)
|
||||
{
|
||||
for (int i = 0; i < count; ++i)
|
||||
|
||||
@@ -11,7 +11,7 @@ static void generateString(FFFontResult* font)
|
||||
ffStrbufAppend(&font->display, &font->fonts[0]);
|
||||
ffStrbufAppendS(&font->display, " [Qt]");
|
||||
|
||||
for(uint8_t i = 1; i < sizeof(font->fonts) / sizeof(font->fonts[0]); i++)
|
||||
for(uint8_t i = 1; i < ARRAY_SIZE(font->fonts); i++)
|
||||
{
|
||||
if(font->fonts[i].length > 0)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
static void generateString(FFFontResult* font)
|
||||
{
|
||||
const char* types[] = { "Caption", "Menu", "Message", "Status" };
|
||||
for(uint32_t i = 0; i < sizeof(types) / sizeof(types[0]); ++i)
|
||||
for(uint32_t i = 0; i < ARRAY_SIZE(types); ++i)
|
||||
{
|
||||
if(i == 0 || !ffStrbufEqual(&font->fonts[i - 1], &font->fonts[i]))
|
||||
{
|
||||
@@ -31,7 +31,7 @@ const char* ffDetectFontImpl(FFFontResult* result)
|
||||
|
||||
LOGFONTW* fonts[4] = { &info.lfCaptionFont, &info.lfMenuFont, &info.lfMessageFont, &info.lfStatusFont };
|
||||
|
||||
for(uint32_t i = 0; i < sizeof(fonts) / sizeof(fonts[0]); ++i)
|
||||
for(uint32_t i = 0; i < ARRAY_SIZE(fonts); ++i)
|
||||
{
|
||||
ffStrbufSetWS(&result->fonts[i], fonts[i]->lfFaceName);
|
||||
if(fonts[i]->lfHeight < 0)
|
||||
|
||||
@@ -13,7 +13,7 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
|
||||
char path[16];
|
||||
for (int i = 0; i < MAX_UHID_JOYS; i++)
|
||||
{
|
||||
snprintf(path, sizeof(path), "/dev/uhid%d", i);
|
||||
snprintf(path, ARRAY_SIZE(path), "/dev/uhid%d", i);
|
||||
FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0) continue;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ static void detectGamepad(FFlist* devices, FFstrbuf* name, FFstrbuf* path)
|
||||
ffStrbufAppendS(path, entry->d_name);
|
||||
ffStrbufAppendS(path, "/capacity"); // /sys/class/input/jsX/device/device/power_supply/XXX/capacity
|
||||
char capacity[32];
|
||||
ssize_t nRead = ffReadFileData(path->chars, sizeof(capacity) - 1, capacity);
|
||||
ssize_t nRead = ffReadFileData(path->chars, ARRAY_SIZE(capacity) - 1, capacity);
|
||||
if (nRead > 0) // Tested with a PS4 controller
|
||||
{
|
||||
capacity[nRead] = '\0';
|
||||
@@ -37,7 +37,7 @@ static void detectGamepad(FFlist* devices, FFstrbuf* name, FFstrbuf* path)
|
||||
}
|
||||
|
||||
ffStrbufAppendS(path, "_level");
|
||||
nRead = ffReadFileData(path->chars, sizeof(capacity) - 1, capacity);
|
||||
nRead = ffReadFileData(path->chars, ARRAY_SIZE(capacity) - 1, capacity);
|
||||
if (nRead > 0) // Tested with a NS Pro controller
|
||||
{
|
||||
// https://github.com/torvalds/linux/blob/52b1853b080a082ec3749c3a9577f6c71b1d4a90/drivers/power/supply/power_supply_sysfs.c#L124
|
||||
|
||||
@@ -114,10 +114,10 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
|
||||
if (!knownGamepad)
|
||||
{
|
||||
wchar_t displayName[126];
|
||||
if (HidD_GetProductString(hHidFile, displayName, sizeof(displayName)))
|
||||
if (HidD_GetProductString(hHidFile, displayName, sizeof(displayName) /*in bytes*/))
|
||||
{
|
||||
wchar_t manufacturer[126];
|
||||
if (HidD_GetManufacturerString(hHidFile, manufacturer, sizeof(manufacturer)))
|
||||
if (HidD_GetManufacturerString(hHidFile, manufacturer, sizeof(manufacturer) /*in bytes*/))
|
||||
{
|
||||
ffStrbufSetWS(&device->name, manufacturer);
|
||||
FF_STRBUF_AUTO_DESTROY displayNameStr = ffStrbufCreateWS(displayName);
|
||||
@@ -132,7 +132,7 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
|
||||
}
|
||||
|
||||
wchar_t serialNumber[127] = L"";
|
||||
if (HidD_GetSerialNumberString(hHidFile, serialNumber, sizeof(serialNumber)))
|
||||
if (HidD_GetSerialNumberString(hHidFile, serialNumber, sizeof(serialNumber) /*in bytes*/))
|
||||
ffStrbufSetWS(&device->serial, serialNumber);
|
||||
|
||||
PHIDP_PREPARSED_DATA preparsedData = NULL;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */)
|
||||
char path[16];
|
||||
for (int i = 0; i < MAX_UHID_JOYS; i++)
|
||||
{
|
||||
snprintf(path, sizeof(path), "/dev/uhid%d", i);
|
||||
snprintf(path, ARRAY_SIZE(path), "/dev/uhid%d", i);
|
||||
FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0) continue;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */)
|
||||
continue;
|
||||
|
||||
char buffer[32]; // `../eventX`
|
||||
ssize_t len = readlinkat(dirfd(dirp), entry->d_name, buffer, sizeof(buffer) - 1);
|
||||
ssize_t len = readlinkat(dirfd(dirp), entry->d_name, buffer, ARRAY_SIZE(buffer) - 1);
|
||||
if (len != strlen("../eventX") || !ffStrStartsWith(buffer, "../event")) continue;
|
||||
buffer[len] = 0;
|
||||
|
||||
|
||||
@@ -198,7 +198,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
|
||||
|
||||
char addressBuffer[32];
|
||||
uint8_t* ptr = (uint8_t*) LLADDR((struct sockaddr_dl *)ifa->ifa_addr);
|
||||
snprintf(addressBuffer, sizeof(addressBuffer), "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
snprintf(addressBuffer, ARRAY_SIZE(addressBuffer), "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]);
|
||||
addNewIp(results, ifa->ifa_name, addressBuffer, -1, isDefaultRoute, flags, false);
|
||||
}
|
||||
@@ -210,7 +210,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
|
||||
|
||||
char addressBuffer[32];
|
||||
uint8_t* ptr = ((struct sockaddr_ll *)ifa->ifa_addr)->sll_addr;
|
||||
snprintf(addressBuffer, sizeof(addressBuffer), "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
snprintf(addressBuffer, ARRAY_SIZE(addressBuffer), "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]);
|
||||
addNewIp(results, ifa->ifa_name, addressBuffer, -1, isDefaultRoute, flags, false);
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
|
||||
bool newIp = true;
|
||||
|
||||
char name[128];
|
||||
WideCharToMultiByte(CP_UTF8, 0, adapter->FriendlyName, -1, name, sizeof(name), NULL, NULL);
|
||||
WideCharToMultiByte(CP_UTF8, 0, adapter->FriendlyName, -1, name, ARRAY_SIZE(name), NULL, NULL);
|
||||
if (options->namePrefix.length && strncmp(name, options->namePrefix.chars, options->namePrefix.length) != 0)
|
||||
continue;
|
||||
|
||||
@@ -114,7 +114,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
|
||||
{
|
||||
char addressBuffer[32];
|
||||
uint8_t* ptr = adapter->PhysicalAddress;
|
||||
snprintf(addressBuffer, sizeof(addressBuffer), "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
snprintf(addressBuffer, ARRAY_SIZE(addressBuffer), "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]);
|
||||
addNewIp(results, name, addressBuffer, -1, newIp, isDefaultRoute);
|
||||
newIp = false;
|
||||
|
||||
@@ -67,7 +67,7 @@ static const char* getMedia(FFMediaResult* result)
|
||||
if(result->playerId.length > 0)
|
||||
{
|
||||
char buf[128];
|
||||
snprintf(buf, sizeof(buf), "name of app id \"%s\"", result->playerId.chars);
|
||||
snprintf(buf, ARRAY_SIZE(buf), "name of app id \"%s\"", result->playerId.chars);
|
||||
ffOsascript(buf, &result->player);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
const char* ffDetectMemory(FFMemoryResult* ram)
|
||||
{
|
||||
char buf[PROC_FILE_BUFFSIZ];
|
||||
ssize_t nRead = ffReadFileData("/proc/meminfo", sizeof(buf) - 1, buf);
|
||||
ssize_t nRead = ffReadFileData("/proc/meminfo", ARRAY_SIZE(buf) - 1, buf);
|
||||
if(nRead < 0)
|
||||
return "ffReadFileData(\"/proc/meminfo\", sizeof(buf)-1, buf)";
|
||||
return "ffReadFileData(\"/proc/meminfo\", ARRAY_SIZE(buf)-1, buf)";
|
||||
buf[nRead] = '\0';
|
||||
|
||||
uint64_t memTotal = 0,
|
||||
|
||||
@@ -13,7 +13,7 @@ const char* ffDetectMouse(FFlist* devices /* List of FFMouseDevice */)
|
||||
char path[16];
|
||||
for (int i = 0; i < MAX_UHID_JOYS; i++)
|
||||
{
|
||||
snprintf(path, sizeof(path), "/dev/uhid%d", i);
|
||||
snprintf(path, ARRAY_SIZE(path), "/dev/uhid%d", i);
|
||||
FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0) continue;
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options)
|
||||
continue;
|
||||
|
||||
char name[128];
|
||||
WideCharToMultiByte(CP_UTF8, 0, adapter->FriendlyName, -1, name, sizeof(name), NULL, NULL);
|
||||
WideCharToMultiByte(CP_UTF8, 0, adapter->FriendlyName, -1, name, ARRAY_SIZE(name), NULL, NULL);
|
||||
if (options->namePrefix.length && strncmp(name, options->namePrefix.chars, options->namePrefix.length) != 0)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ static const char* openCLHandleData(OpenCLData* data, FFOpenCLResult* result)
|
||||
{
|
||||
cl_platform_id platforms[32];
|
||||
cl_uint numPlatforms = 0;
|
||||
cl_int ret = data->ffclGetPlatformIDs(sizeof(platforms) / sizeof(platforms[0]), platforms, &numPlatforms);
|
||||
cl_int ret = data->ffclGetPlatformIDs(ARRAY_SIZE(platforms), platforms, &numPlatforms);
|
||||
if (ret != CL_SUCCESS)
|
||||
{
|
||||
switch (ret)
|
||||
@@ -77,7 +77,7 @@ static const char* openCLHandleData(OpenCLData* data, FFOpenCLResult* result)
|
||||
}
|
||||
|
||||
cl_device_id deviceIDs[32];
|
||||
cl_uint numDevices = (cl_uint) (sizeof(deviceIDs) / sizeof(deviceIDs[0]));
|
||||
cl_uint numDevices = (cl_uint) ARRAY_SIZE(deviceIDs);
|
||||
if (data->ffclGetDeviceIDs(platforms[iplat], CL_DEVICE_TYPE_GPU, numDevices, deviceIDs, &numDevices) != CL_SUCCESS)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ static const char* wglHandlePixelFormat(WGLData* wglData, HWND hWnd)
|
||||
{
|
||||
PIXELFORMATDESCRIPTOR pfd =
|
||||
{
|
||||
sizeof(PIXELFORMATDESCRIPTOR),
|
||||
sizeof(pfd),
|
||||
1,
|
||||
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, //Flags
|
||||
PFD_TYPE_RGBA, // The kind of framebuffer. RGBA or palette.
|
||||
|
||||
@@ -58,8 +58,8 @@ static void detectChoco(FF_MAYBE_UNUSED FFPackagesResult* result)
|
||||
return;
|
||||
|
||||
char chocoPath[MAX_PATH + 3];
|
||||
char* pend = ffStrCopyN(chocoPath, chocoInstall, sizeof(chocoPath));
|
||||
ffStrCopyN(pend, "/lib/*", sizeof(chocoPath) - (pend - chocoPath));
|
||||
char* pend = ffStrCopyN(chocoPath, chocoInstall, ARRAY_SIZE(chocoPath));
|
||||
ffStrCopyN(pend, "/lib/*", ARRAY_SIZE(chocoPath) - (size_t) (pend - chocoPath));
|
||||
result->choco = getNumElements(chocoPath, FILE_ATTRIBUTE_DIRECTORY, "choco");
|
||||
}
|
||||
|
||||
@@ -71,8 +71,8 @@ static void detectPacman(FFPackagesResult* result)
|
||||
|
||||
// MSYS2
|
||||
char pacmanPath[MAX_PATH + 3];
|
||||
strcpy(pacmanPath, msystemPrefix);
|
||||
strncat(pacmanPath, "/../var/lib/pacman/local/*", sizeof(pacmanPath) - 1 - strlen(pacmanPath));
|
||||
char* pend = ffStrCopyN(pacmanPath, msystemPrefix, ARRAY_SIZE(pacmanPath));
|
||||
ffStrCopyN(pend, "/../var/lib/pacman/local/*", ARRAY_SIZE(pacmanPath) - (size_t) (pend - pacmanPath));
|
||||
result->pacman = getNumElements(pacmanPath, FILE_ATTRIBUTE_DIRECTORY, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ static double detectNvmeTemp(int devfd)
|
||||
{
|
||||
pathHwmon[strlen("hwmon")] = c;
|
||||
char buffer[64];
|
||||
ssize_t size = ffReadFileDataRelative(devfd, pathHwmon, sizeof(buffer), buffer);
|
||||
ssize_t size = ffReadFileDataRelative(devfd, pathHwmon, ARRAY_SIZE(buffer), buffer);
|
||||
if (size > 0)
|
||||
{
|
||||
buffer[size] = '\0';
|
||||
@@ -58,7 +58,7 @@ static void parsePhysicalDisk(int dfd, const char* devName, FFPhysicalDiskOption
|
||||
if (!multiNs)
|
||||
{
|
||||
char pathSysBlock[32];
|
||||
snprintf(pathSysBlock, sizeof(pathSysBlock), "/dev/nvme%dn2", devid);
|
||||
snprintf(pathSysBlock, ARRAY_SIZE(pathSysBlock), "/dev/nvme%dn2", devid);
|
||||
multiNs = access(pathSysBlock, F_OK) == 0;
|
||||
}
|
||||
if (multiNs)
|
||||
@@ -81,7 +81,7 @@ static void parsePhysicalDisk(int dfd, const char* devName, FFPhysicalDiskOption
|
||||
{
|
||||
ffStrbufInit(&device->interconnect);
|
||||
char pathSysDeviceReal[PATH_MAX];
|
||||
ssize_t pathLength = readlinkat(dfd, "device", pathSysDeviceReal, sizeof(pathSysDeviceReal) - 1);
|
||||
ssize_t pathLength = readlinkat(dfd, "device", pathSysDeviceReal, ARRAY_SIZE(pathSysDeviceReal) - 1);
|
||||
if (pathLength > 0)
|
||||
{
|
||||
pathSysDeviceReal[pathLength] = '\0';
|
||||
@@ -110,7 +110,7 @@ static void parsePhysicalDisk(int dfd, const char* devName, FFPhysicalDiskOption
|
||||
|
||||
{
|
||||
char blkSize[32];
|
||||
ssize_t fileSize = ffReadFileDataRelative(dfd, "size", sizeof(blkSize) - 1, blkSize);
|
||||
ssize_t fileSize = ffReadFileDataRelative(dfd, "size", ARRAY_SIZE(blkSize) - 1, blkSize);
|
||||
if (fileSize > 0)
|
||||
{
|
||||
blkSize[fileSize] = 0;
|
||||
@@ -169,8 +169,8 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options)
|
||||
if (devName[0] == '.')
|
||||
continue;
|
||||
|
||||
char pathSysBlock[sizeof("/sys/block/") + sizeof(sysBlockEntry->d_name)];
|
||||
snprintf(pathSysBlock, sizeof(pathSysBlock), "/sys/block/%s", devName);
|
||||
char pathSysBlock[ARRAY_SIZE("/sys/block/") + ARRAY_SIZE(sysBlockEntry->d_name)];
|
||||
snprintf(pathSysBlock, ARRAY_SIZE(pathSysBlock), "/sys/block/%s", devName);
|
||||
|
||||
int dfd = openat(dirfd(sysBlockDirp), devName, O_RDONLY | O_CLOEXEC | O_PATH | O_DIRECTORY);
|
||||
if (dfd > 0) parsePhysicalDisk(dfd, devName, options, result);
|
||||
|
||||
@@ -15,7 +15,7 @@ const char* ffDetectProcesses(uint32_t* result)
|
||||
int request[] = {CTL_KERN, KERN_PROC, KERN_PROC_PROC};
|
||||
size_t length;
|
||||
|
||||
if(sysctl(request, sizeof(request) / sizeof(*request), NULL, &length, NULL, 0) != 0)
|
||||
if(sysctl(request, ARRAY_SIZE(request), NULL, &length, NULL, 0) != 0)
|
||||
return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_PROC}) failed";
|
||||
|
||||
*result = (uint32_t)(length / sizeof(struct kinfo_proc));
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
const char* ffDetectSwap(FFSwapResult* swap)
|
||||
{
|
||||
int mib[16];
|
||||
size_t mibsize = sizeof(mib) / sizeof(*mib);
|
||||
size_t mibsize = ARRAY_SIZE(mib);
|
||||
if (sysctlnametomib("vm.swap_info", mib, &mibsize) < 0)
|
||||
return "sysctlnametomib(\"vm.swap_info\") failed";
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@ const char* ffDetectSwap(FFSwapResult* swap)
|
||||
{
|
||||
// #620
|
||||
char buf[PROC_FILE_BUFFSIZ];
|
||||
ssize_t nRead = ffReadFileData("/proc/meminfo", sizeof(buf) - 1, buf);
|
||||
ssize_t nRead = ffReadFileData("/proc/meminfo", ARRAY_SIZE(buf) - 1, buf);
|
||||
if(nRead < 0)
|
||||
return "ffReadFileData(\"/proc/meminfo\", sizeof(buf)-1, buf)";
|
||||
return "ffReadFileData(\"/proc/meminfo\", ARRAY_SIZE(buf)-1, buf)";
|
||||
buf[nRead] = '\0';
|
||||
|
||||
uint64_t swapTotal = 0, swapFree = 0;
|
||||
@@ -19,7 +19,7 @@ const char* ffDetectSwap(FFSwapResult* swap)
|
||||
char *token = NULL;
|
||||
if ((token = strstr(buf, "SwapTotal:")) != NULL)
|
||||
swapTotal = strtoul(token + strlen("SwapTotal:"), NULL, 10);
|
||||
|
||||
|
||||
if ((token = strstr(buf, "SwapFree:")) != NULL)
|
||||
swapFree = strtoul(token + strlen("SwapFree:"), NULL, 10);
|
||||
|
||||
|
||||
@@ -99,17 +99,17 @@ static void detectFromWindowsTerminal(const FFstrbuf* terminalExe, FFTerminalFon
|
||||
{
|
||||
char jsonPath[MAX_PATH + 1];
|
||||
char* pathEnd = ffStrCopyN(jsonPath, terminalExe->chars, ffStrbufLastIndexC(terminalExe, '\\') + 1);
|
||||
ffStrCopyN(pathEnd, ".portable", sizeof(jsonPath) - (size_t) (pathEnd - jsonPath) - 1);
|
||||
ffStrCopyN(pathEnd, ".portable", ARRAY_SIZE(jsonPath) - (size_t) (pathEnd - jsonPath) - 1);
|
||||
|
||||
if(ffPathExists(jsonPath, FF_PATHTYPE_ANY))
|
||||
{
|
||||
ffStrCopyN(pathEnd, "settings\\settings.json", sizeof(jsonPath) - (size_t) (pathEnd - jsonPath) - 1);
|
||||
ffStrCopyN(pathEnd, "settings\\settings.json", ARRAY_SIZE(jsonPath) - (size_t) (pathEnd - jsonPath) - 1);
|
||||
if(!ffAppendFileBuffer(jsonPath, &json))
|
||||
error = "Error reading Windows Terminal portable settings JSON file";
|
||||
}
|
||||
else if(SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, jsonPath)))
|
||||
{
|
||||
size_t remaining = sizeof(jsonPath) - strlen(jsonPath) - 1;
|
||||
size_t remaining = ARRAY_SIZE(jsonPath) - strlen(jsonPath) - 1;
|
||||
if(ffStrbufContainIgnCaseS(terminalExe, "_8wekyb3d8bbwe\\"))
|
||||
{
|
||||
// Microsoft Store version
|
||||
@@ -175,7 +175,7 @@ static void detectFromWindowsTerminal(const FFstrbuf* terminalExe, FFTerminalFon
|
||||
else
|
||||
{
|
||||
char sizeStr[16];
|
||||
snprintf(sizeStr, sizeof(sizeStr), "%g", size);
|
||||
snprintf(sizeStr, ARRAY_SIZE(sizeStr), "%g", size);
|
||||
ffFontInitValues(&terminalFont->font, name.chars, sizeStr);
|
||||
}
|
||||
}
|
||||
@@ -226,7 +226,7 @@ static void detectConEmu(FFTerminalFontResult* terminalFont)
|
||||
FF_STRBUF_AUTO_DESTROY fontSize = ffStrbufCreate();
|
||||
|
||||
const char* paths[] = { "ConEmuDir", "ConEmuBaseDir", "APPDATA" };
|
||||
for (uint32_t i = 0; i < sizeof(paths) / sizeof(paths[0]); ++i)
|
||||
for (uint32_t i = 0; i < ARRAY_SIZE(paths); ++i)
|
||||
{
|
||||
ffStrbufSetS(&path, getenv(paths[i]));
|
||||
if(path.length > 0)
|
||||
|
||||
@@ -579,16 +579,16 @@ static bool getTerminalVersionKitty(FFstrbuf* exe, FFstrbuf* version)
|
||||
char buffer[1024] = {};
|
||||
if (
|
||||
#ifdef __linux__
|
||||
ffReadFileData(FASTFETCH_TARGET_DIR_USR "/lib64/kitty/kitty/constants.py", sizeof(buffer) - 1, buffer) ||
|
||||
ffReadFileData(FASTFETCH_TARGET_DIR_USR "/lib/kitty/kitty/constants.py", sizeof(buffer) - 1, buffer)
|
||||
ffReadFileData(FASTFETCH_TARGET_DIR_USR "/lib64/kitty/kitty/constants.py", ARRAY_SIZE(buffer) - 1, buffer) ||
|
||||
ffReadFileData(FASTFETCH_TARGET_DIR_USR "/lib/kitty/kitty/constants.py", ARRAY_SIZE(buffer) - 1, buffer)
|
||||
#else
|
||||
ffReadFileData(_PATH_LOCALBASE "/share/kitty/kitty/constants.py", sizeof(buffer) - 1, buffer)
|
||||
ffReadFileData(_PATH_LOCALBASE "/share/kitty/kitty/constants.py", ARRAY_SIZE(buffer) - 1, buffer)
|
||||
#endif
|
||||
)
|
||||
{
|
||||
// Starts from version 0.17.0
|
||||
// https://github.com/kovidgoyal/kitty/blob/master/kitty/constants.py#L25
|
||||
const char* p = memmem(buffer, sizeof(buffer) - 1, "version: Version = Version(", strlen("version: Version = Version("));
|
||||
const char* p = memmem(buffer, ARRAY_SIZE(buffer) - 1, "version: Version = Version(", strlen("version: Version = Version("));
|
||||
if (p)
|
||||
{
|
||||
p += strlen("version: Version = Version(");
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
const char* ffDetectUptime(FFUptimeResult* result)
|
||||
{
|
||||
#ifndef __ANDROID__ // cat: /proc/uptime: Permission denied
|
||||
|
||||
|
||||
// #620
|
||||
char buf[64];
|
||||
ssize_t nRead = ffReadFileData("/proc/uptime", sizeof(buf) - 1, buf);
|
||||
ssize_t nRead = ffReadFileData("/proc/uptime", ARRAY_SIZE(buf) - 1, buf);
|
||||
if(nRead > 0)
|
||||
{
|
||||
buf[nRead] = '\0';
|
||||
|
||||
@@ -123,7 +123,7 @@ static const char* detectVulkan(FFVulkanResult* result)
|
||||
instanceVersion.major = 1;
|
||||
|
||||
VkPhysicalDevice physicalDevices[128];
|
||||
uint32_t physicalDeviceCount = (uint32_t) (sizeof(physicalDevices) / sizeof(*physicalDevices));
|
||||
uint32_t physicalDeviceCount = (uint32_t) ARRAY_SIZE(physicalDevices);
|
||||
res = ffvkEnumeratePhysicalDevices(vkInstance, &physicalDeviceCount, physicalDevices);
|
||||
if(res != VK_SUCCESS)
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
const char* ffDetectWMPlugin(FFstrbuf* pluginName)
|
||||
{
|
||||
int request[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL};
|
||||
u_int requestLength = sizeof(request) / sizeof(*request);
|
||||
u_int requestLength = ARRAY_SIZE(request);
|
||||
|
||||
size_t length = 0;
|
||||
FF_AUTO_FREE struct kinfo_proc* processes = ffSysctlGetData(request, requestLength, &length);
|
||||
|
||||
@@ -25,6 +25,13 @@
|
||||
#include "options/display.h"
|
||||
#include "options/general.h"
|
||||
|
||||
#if __has_builtin(__builtin_types_compatible_p)
|
||||
#define ARRAY_SIZE(x) ({ static_assert(!__builtin_types_compatible_p(__typeof__(x), __typeof__(&*(x))), "Must not be a pointer"); sizeof(x) / sizeof(*(x)); })
|
||||
#else
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct FFconfig
|
||||
{
|
||||
FFOptionsLogo logo;
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ int main(void)
|
||||
&options->colors,
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < sizeof(modules) / sizeof(modules[0]); i++)
|
||||
for (size_t i = 0; i < ARRAY_SIZE(modules); i++)
|
||||
((const FFModuleBaseInfo*) modules[i])->printModule(modules[i]);
|
||||
|
||||
ffFinish();
|
||||
|
||||
@@ -39,7 +39,7 @@ void ffPrintCPU(FFCPUOptions* options)
|
||||
if (options->showPeCoreCount)
|
||||
{
|
||||
uint32_t typeCount = 0;
|
||||
while (cpu.coreTypes[typeCount].count != 0 && typeCount < sizeof(cpu.coreTypes) / sizeof(cpu.coreTypes[0])) typeCount++;
|
||||
while (cpu.coreTypes[typeCount].count != 0 && typeCount < ARRAY_SIZE(cpu.coreTypes)) typeCount++;
|
||||
if (typeCount > 0)
|
||||
{
|
||||
qsort(cpu.coreTypes, typeCount, sizeof(cpu.coreTypes[0]), (void*) sortCores);
|
||||
|
||||
@@ -107,7 +107,7 @@ void ffPrintDateTime(FFDateTimeOptions* options)
|
||||
}
|
||||
|
||||
char buffer[32];
|
||||
if (strftime(buffer, sizeof(buffer), "%F %T", tm) == 0) //yyyy-MM-dd HH:mm:ss
|
||||
if (strftime(buffer, ARRAY_SIZE(buffer), "%F %T", tm) == 0) //yyyy-MM-dd HH:mm:ss
|
||||
{
|
||||
ffPrintError(FF_DATETIME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "strftime() failed");
|
||||
return;
|
||||
|
||||
@@ -146,9 +146,9 @@ void ffPrintDisplay(FFDisplayOptions* options)
|
||||
if(result->refreshRate > 0)
|
||||
{
|
||||
if(options->preciseRefreshRate)
|
||||
snprintf(refreshRate, sizeof(refreshRate), "%g", ((int) (result->refreshRate * 1000 + 0.5)) / 1000.0);
|
||||
snprintf(refreshRate, ARRAY_SIZE(refreshRate), "%g", ((int) (result->refreshRate * 1000 + 0.5)) / 1000.0);
|
||||
else
|
||||
snprintf(refreshRate, sizeof(refreshRate), "%i", (uint32_t) (result->refreshRate + 0.5));
|
||||
snprintf(refreshRate, ARRAY_SIZE(refreshRate), "%i", (uint32_t) (result->refreshRate + 0.5));
|
||||
}
|
||||
else
|
||||
refreshRate[0] = 0;
|
||||
@@ -157,7 +157,7 @@ void ffPrintDisplay(FFDisplayOptions* options)
|
||||
if (result->serial)
|
||||
{
|
||||
const uint8_t* nums = (uint8_t*) &result->serial;
|
||||
snprintf(buf, sizeof(buf), "%2X-%2X-%2X-%2X", nums[0], nums[1], nums[2], nums[3]);
|
||||
snprintf(buf, ARRAY_SIZE(buf), "%2X-%2X-%2X-%2X", nums[0], nums[1], nums[2], nums[3]);
|
||||
}
|
||||
else
|
||||
buf[0] = '\0';
|
||||
|
||||
@@ -63,7 +63,7 @@ void ffPrintMedia(FFMediaOptions* options)
|
||||
"[Lyric Video]", "[Official Lyric Video]", "[Lyrics]",
|
||||
"| Lyric Video", "| Official Lyric Video", "| Lyrics",
|
||||
};
|
||||
ffStrbufRemoveStrings(&songPretty, sizeof(removeStrings) / sizeof(removeStrings[0]), removeStrings);
|
||||
ffStrbufRemoveStrings(&songPretty, ARRAY_SIZE(removeStrings), removeStrings);
|
||||
ffStrbufTrimRight(&songPretty, ' ');
|
||||
|
||||
if(songPretty.length == 0)
|
||||
|
||||
@@ -32,8 +32,8 @@ void ffPrintTerminalTheme(FFTerminalThemeOptions* options)
|
||||
char fg[32], bg[32];
|
||||
const char* fgType = result.fg.dark ? "Dark" : "Light";
|
||||
const char* bgType = result.bg.dark ? "Dark" : "Light";
|
||||
snprintf(fg, sizeof(fg), "#%02" PRIX16 "%02" PRIX16 "%02" PRIX16, result.fg.r, result.fg.g, result.fg.b);
|
||||
snprintf(bg, sizeof(bg), "#%02" PRIX16 "%02" PRIX16 "%02" PRIX16, result.bg.r, result.bg.g, result.bg.b);
|
||||
snprintf(fg, ARRAY_SIZE(fg), "#%02" PRIX16 "%02" PRIX16 "%02" PRIX16, result.fg.r, result.fg.g, result.fg.b);
|
||||
snprintf(bg, ARRAY_SIZE(bg), "#%02" PRIX16 "%02" PRIX16 "%02" PRIX16, result.bg.r, result.bg.g, result.bg.b);
|
||||
FF_PRINT_FORMAT_CHECKED(FF_TERMINALTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_TERMINALTHEME_NUM_FORMAT_ARGS, ((FFformatarg[]){
|
||||
FF_FORMAT_ARG(fg, "fg-color"),
|
||||
FF_FORMAT_ARG(fgType, "fg-type"),
|
||||
|
||||
@@ -139,7 +139,7 @@ static void getUserName(FFPlatform* platform)
|
||||
else
|
||||
{
|
||||
wchar_t buffer[128];
|
||||
DWORD len = sizeof(buffer) / sizeof(*buffer);
|
||||
DWORD len = ARRAY_SIZE(buffer);
|
||||
if(GetUserNameW(buffer, &len))
|
||||
ffStrbufSetWS(&platform->userName, buffer);
|
||||
}
|
||||
@@ -148,7 +148,7 @@ static void getUserName(FFPlatform* platform)
|
||||
static void getHostName(FFPlatform* platform)
|
||||
{
|
||||
wchar_t buffer[128];
|
||||
DWORD len = sizeof(buffer) / sizeof(*buffer);
|
||||
DWORD len = ARRAY_SIZE(buffer);
|
||||
if(GetComputerNameExW(ComputerNameDnsHostname, buffer, &len))
|
||||
ffStrbufSetWS(&platform->hostName, buffer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user