Refactored read methods

This commit is contained in:
Linus Dierheimer
2022-06-20 16:27:33 +02:00
parent 6e731c80d0
commit 8fa09ca093
12 changed files with 53 additions and 39 deletions
+7 -7
View File
@@ -23,7 +23,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
//type must exist and be "Battery"
ffStrbufAppendS(dir, "/type");
ffGetFileContent(dir->chars, &testBatteryBuffer);
ffGetFileBuffer(dir->chars, &testBatteryBuffer);
ffStrbufSubstrBefore(dir, dirLength);
if(ffStrbufIgnCaseCompS(&testBatteryBuffer, "Battery") != 0)
@@ -34,7 +34,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
//scope may not exist or must not be "Device"
ffStrbufAppendS(dir, "/scope");
ffGetFileContent(dir->chars, &testBatteryBuffer);
ffGetFileBuffer(dir->chars, &testBatteryBuffer);
ffStrbufSubstrBefore(dir, dirLength);
if(ffStrbufIgnCaseCompS(&testBatteryBuffer, "Device") == 0)
@@ -49,7 +49,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
//capacity must exist and be not empty
ffStrbufInit(&result->capacity);
ffStrbufAppendS(dir, "/capacity");
ffGetFileContent(dir->chars, &result->capacity);
ffGetFileBuffer(dir->chars, &result->capacity);
ffStrbufSubstrBefore(dir, dirLength);
if(result->capacity.length == 0)
@@ -63,22 +63,22 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
ffStrbufInit(&result->manufacturer);
ffStrbufAppendS(dir, "/manufacturer");
ffGetFileContent(dir->chars, &result->manufacturer);
ffGetFileBuffer(dir->chars, &result->manufacturer);
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufInit(&result->modelName);
ffStrbufAppendS(dir, "/model_name");
ffGetFileContent(dir->chars, &result->modelName);
ffGetFileBuffer(dir->chars, &result->modelName);
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufInit(&result->technology);
ffStrbufAppendS(dir, "/technology");
ffGetFileContent(dir->chars, &result->technology);
ffGetFileBuffer(dir->chars, &result->technology);
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufInit(&result->status);
ffStrbufAppendS(dir, "/status");
ffGetFileContent(dir->chars, &result->status);
ffGetFileBuffer(dir->chars, &result->status);
ffStrbufSubstrBefore(dir, dirLength);
}
+2 -2
View File
@@ -10,9 +10,9 @@ static double getGhz(const char* policyFile, const char* cpuFile)
FFstrbuf content;
ffStrbufInit(&content);
ffGetFileContent(policyFile, &content);
ffGetFileBuffer(policyFile, &content);
if(content.length == 0)
ffGetFileContent(cpuFile, &content);
ffGetFileBuffer(cpuFile, &content);
double herz = ffStrbufToDouble(&content);
+4 -4
View File
@@ -39,10 +39,10 @@ static bool hostValueSet(FFstrbuf* value)
static void getHostValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer)
{
ffGetFileContent(devicesPath, buffer);
ffGetFileBuffer(devicesPath, buffer);
if(buffer->length == 0)
ffGetFileContent(classPath, buffer);
ffGetFileBuffer(classPath, buffer);
}
#endif
@@ -67,10 +67,10 @@ void ffPrintHost(FFinstance* instance)
getHostValue("/sys/devices/virtual/dmi/id/product_name", "/sys/class/dmi/id/product_name", &product_name);
if(product_name.length == 0)
ffGetFileContent("/sys/firmware/devicetree/base/model", &product_name);
ffGetFileBuffer("/sys/firmware/devicetree/base/model", &product_name);
if(product_name.length == 0)
ffGetFileContent("/tmp/sysinfo/model", &product_name);
ffGetFileBuffer("/tmp/sysinfo/model", &product_name);
if(ffStrbufStartsWithS(&product_name, "Standard PC"))
{