mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:14:37 +02:00
FFstrbuf: change ffStrbufToUInt16 to more general function ffStrbufToUInt
This commit is contained in:
@@ -25,7 +25,7 @@ const char* ffDetectChassis(FFChassisResult* result)
|
||||
|
||||
if(result->type.length)
|
||||
{
|
||||
const char* typeStr = ffChassisTypeToString(ffStrbufToUInt16(&result->type, 9999));
|
||||
const char* typeStr = ffChassisTypeToString((uint32_t) ffStrbufToUInt(&result->type, 9999));
|
||||
if(typeStr)
|
||||
ffStrbufSetS(&result->type, typeStr);
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
|
||||
const char* error = parseCpuInfo(cpu, &physicalCoresBuffer, &cpuMHz, &cpuIsa, &cpuUarch);
|
||||
if (error) return error;
|
||||
|
||||
cpu->coresPhysical = ffStrbufToUInt16(&physicalCoresBuffer, 1);
|
||||
cpu->coresPhysical = (uint16_t) ffStrbufToUInt(&physicalCoresBuffer, 1);
|
||||
|
||||
cpu->coresLogical = (uint16_t) get_nprocs_conf();
|
||||
cpu->coresOnline = (uint16_t) get_nprocs();
|
||||
|
||||
@@ -80,9 +80,9 @@ static bool detectWithGetprop(FFDisplayServerResult* ds)
|
||||
ffStrbufContainC(&buffer, ','))
|
||||
{
|
||||
// 1440,3200,560 => width,height,ppi
|
||||
uint32_t width = ffStrbufToUInt16(&buffer, 0);
|
||||
uint32_t width = (uint32_t) ffStrbufToUInt(&buffer, 0);
|
||||
ffStrbufSubstrAfterFirstC(&buffer, ',');
|
||||
uint32_t height = ffStrbufToUInt16(&buffer, 0);
|
||||
uint32_t height = (uint32_t) ffStrbufToUInt(&buffer, 0);
|
||||
return ffdsAppendDisplay(ds,
|
||||
width,
|
||||
height,
|
||||
|
||||
+3
-3
@@ -431,11 +431,11 @@ double ffStrbufToDouble(const FFstrbuf* strbuf)
|
||||
return str_end == strbuf->chars ? 0.0/0.0 : result;
|
||||
}
|
||||
|
||||
uint16_t ffStrbufToUInt16(const FFstrbuf* strbuf, uint16_t defaultValue)
|
||||
uint64_t ffStrbufToUInt(const FFstrbuf* strbuf, uint64_t defaultValue)
|
||||
{
|
||||
char* str_end;
|
||||
unsigned long result = strtoul(strbuf->chars, &str_end, 10);
|
||||
return str_end == strbuf->chars || result > UINT16_MAX ? defaultValue : (uint16_t)result;
|
||||
unsigned long long result = strtoull(strbuf->chars, &str_end, 10);
|
||||
return str_end == strbuf->chars ? defaultValue : (uint64_t)result;
|
||||
}
|
||||
|
||||
void ffStrbufUpperCase(FFstrbuf* strbuf)
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ void ffStrbufWriteTo(const FFstrbuf* strbuf, FILE* file);
|
||||
void ffStrbufPutTo(const FFstrbuf* strbuf, FILE* file);
|
||||
|
||||
FF_C_NODISCARD double ffStrbufToDouble(const FFstrbuf* strbuf);
|
||||
FF_C_NODISCARD uint16_t ffStrbufToUInt16(const FFstrbuf* strbuf, uint16_t defaultValue);
|
||||
FF_C_NODISCARD uint64_t ffStrbufToUInt(const FFstrbuf* strbuf, uint64_t defaultValue);
|
||||
|
||||
void ffStrbufUpperCase(FFstrbuf* strbuf);
|
||||
void ffStrbufLowerCase(FFstrbuf* strbuf);
|
||||
|
||||
+1
-1
@@ -123,7 +123,7 @@ int main(void)
|
||||
//toNumber
|
||||
|
||||
VERIFY(ffStrbufToDouble(&strbuf) == 123456789.0);
|
||||
VERIFY(ffStrbufToUInt16(&strbuf, 999) == 999); //overflow
|
||||
VERIFY(ffStrbufToUInt(&strbuf, 999) == 123456789);
|
||||
|
||||
//countC
|
||||
|
||||
|
||||
Reference in New Issue
Block a user