StringUtil: rename ffStrCopy and correctly reflect its usage

This commit is contained in:
李通洲
2024-11-11 18:02:23 +08:00
parent c368908b7d
commit 7c8250c68c
7 changed files with 21 additions and 21 deletions
+7 -7
View File
@@ -20,35 +20,35 @@ const char* ffDetectCPUCache(FFCPUCacheResult* result)
{
*pNum = (char) ('0' + i);
ffStrCopyN(pSubkey, "physicalcpu", lenLeft);
ffStrCopy(pSubkey, "physicalcpu", lenLeft);
uint32_t ncpu = (uint32_t) ffSysctlGetInt(sysctlKey, 0);
if (ncpu <= 0) continue;
ffStrCopyN(pSubkey, "l1icachesize", lenLeft);
ffStrCopy(pSubkey, "l1icachesize", lenLeft);
uint32_t size = (uint32_t) ffSysctlGetInt(sysctlKey, 0);
if (size)
ffCPUCacheAddItem(result, 1, size, lineSize, FF_CPU_CACHE_TYPE_INSTRUCTION)->num = ncpu;
ffStrCopyN(pSubkey, "l1dcachesize", lenLeft);
ffStrCopy(pSubkey, "l1dcachesize", lenLeft);
size = (uint32_t) ffSysctlGetInt(sysctlKey, 0);
if (size)
ffCPUCacheAddItem(result, 1, size, lineSize, FF_CPU_CACHE_TYPE_DATA)->num = ncpu;
ffStrCopyN(pSubkey, "l2cachesize", lenLeft);
ffStrCopy(pSubkey, "l2cachesize", lenLeft);
size = (uint32_t) ffSysctlGetInt(sysctlKey, 0);
if (size)
{
ffStrCopyN(pSubkey, "cpusperl2", lenLeft);
ffStrCopy(pSubkey, "cpusperl2", lenLeft);
uint32_t cpuSper = (uint32_t) ffSysctlGetInt(sysctlKey, 0);
if (cpuSper)
ffCPUCacheAddItem(result, 2, size, lineSize, FF_CPU_CACHE_TYPE_UNIFIED)->num = ncpu / cpuSper;
}
ffStrCopyN(pSubkey, "l3cachesize", lenLeft);
ffStrCopy(pSubkey, "l3cachesize", lenLeft);
size = (uint32_t) ffSysctlGetInt(sysctlKey, 0);
if (size)
{
ffStrCopyN(pSubkey, "cpusperl3", lenLeft);
ffStrCopy(pSubkey, "cpusperl3", lenLeft);
uint32_t cpuSper = (uint32_t) ffSysctlGetInt(sysctlKey, 0);
if (cpuSper)
ffCPUCacheAddItem(result, 3, size, lineSize, FF_CPU_CACHE_TYPE_UNIFIED)->num = ncpu / cpuSper;
+1 -1
View File
@@ -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, ARRAY_SIZE(drmKeyBuffer));
ffStrCopy(drmKeyBuffer, entry->d_name, ARRAY_SIZE(drmKeyBuffer));
drmKey = drmKeyBuffer;
break;
}
+2 -2
View File
@@ -231,7 +231,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
FF_LIST_FOR_EACH(FFLocalIpResult, iface, *results)
{
struct ifreq ifr;
ffStrCopyN(ifr.ifr_name, iface->name.chars, IFNAMSIZ);
ffStrCopy(ifr.ifr_name, iface->name.chars, IFNAMSIZ);
if (options->showType & FF_LOCALIP_TYPE_MTU_BIT)
{
@@ -248,7 +248,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
iface->speed = (edata.speed_hi << 16) | edata.speed; // ethtool_cmd_speed is not available on Android
#elif __FreeBSD__ || __APPLE__ || __OpenBSD__ || __NetBSD__
struct ifmediareq ifmr = {};
ffStrCopyN(ifmr.ifm_name, iface->name.chars, IFNAMSIZ);
ffStrCopy(ifmr.ifm_name, iface->name.chars, IFNAMSIZ);
if (ioctl(sockfd, SIOCGIFMEDIA, &ifmr) == 0 && (IFM_TYPE(ifmr.ifm_active) & IFM_ETHER))
{
switch (IFM_SUBTYPE(ifmr.ifm_active))
+4 -4
View File
@@ -58,8 +58,8 @@ static void detectChoco(FF_MAYBE_UNUSED FFPackagesResult* result)
return;
char chocoPath[MAX_PATH + 3];
char* pend = ffStrCopyN(chocoPath, chocoInstall, ARRAY_SIZE(chocoPath));
ffStrCopyN(pend, "/lib/*", ARRAY_SIZE(chocoPath) - (size_t) (pend - chocoPath));
char* pend = ffStrCopy(chocoPath, chocoInstall, ARRAY_SIZE(chocoPath));
ffStrCopy(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];
char* pend = ffStrCopyN(pacmanPath, msystemPrefix, ARRAY_SIZE(pacmanPath));
ffStrCopyN(pend, "/../var/lib/pacman/local/*", ARRAY_SIZE(pacmanPath) - (size_t) (pend - pacmanPath));
char* pend = ffStrCopy(pacmanPath, msystemPrefix, ARRAY_SIZE(pacmanPath));
ffStrCopy(pend, "/../var/lib/pacman/local/*", ARRAY_SIZE(pacmanPath) - (size_t) (pend - pacmanPath));
result->pacman = getNumElements(pacmanPath, FILE_ATTRIBUTE_DIRECTORY, NULL);
}
@@ -98,12 +98,12 @@ static void detectFromWindowsTerminal(const FFstrbuf* terminalExe, FFTerminalFon
if(terminalExe && terminalExe->length > 0 && !ffStrbufEqualS(terminalExe, "Windows Terminal"))
{
char jsonPath[MAX_PATH + 1];
char* pathEnd = ffStrCopyN(jsonPath, terminalExe->chars, ffStrbufLastIndexC(terminalExe, '\\') + 1);
ffStrCopyN(pathEnd, ".portable", ARRAY_SIZE(jsonPath) - (size_t) (pathEnd - jsonPath) - 1);
char* pathEnd = ffStrCopy(jsonPath, terminalExe->chars, ffStrbufLastIndexC(terminalExe, '\\') + 1);
ffStrCopy(pathEnd, ".portable", ARRAY_SIZE(jsonPath) - (size_t) (pathEnd - jsonPath) - 1);
if(ffPathExists(jsonPath, FF_PATHTYPE_ANY))
{
ffStrCopyN(pathEnd, "settings\\settings.json", ARRAY_SIZE(jsonPath) - (size_t) (pathEnd - jsonPath) - 1);
ffStrCopy(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";
}
+1 -1
View File
@@ -190,7 +190,7 @@ static const char* detectWifiWithIoctls(FFWifiResult* item)
return "socket() failed";
struct iwreq iwr;
ffStrCopyN(iwr.ifr_name, item->inf.description.chars, IFNAMSIZ);
ffStrCopy(iwr.ifr_name, item->inf.description.chars, IFNAMSIZ);
ffStrbufEnsureFree(&item->conn.ssid, IW_ESSID_MAX_SIZE);
iwr.u.essid.pointer = (caddr_t) item->conn.ssid.chars;
iwr.u.essid.length = IW_ESSID_MAX_SIZE + 1;
+3 -3
View File
@@ -80,12 +80,12 @@ static inline bool ffCharIsDigit(char c)
return '0' <= c && c <= '9';
}
static inline char* ffStrCopyN(char* __restrict__ dst, const char* __restrict__ src, size_t nDst)
// Copies at most (dstBufSiz - 1) bytes from src to dst; dst is always null-terminated
static inline char* ffStrCopy(char* __restrict__ dst, const char* __restrict__ src, size_t dstBufSiz)
{
assert(dst != NULL);
if (__builtin_expect(dst == NULL, false)) return dst;
size_t len = strnlen(src, nDst - 1);
size_t len = strnlen(src, dstBufSiz - 1);
memcpy(dst, src, len);
dst[len] = '\0';
return dst + len;