diff --git a/src/common/caching.c b/src/common/caching.c index ffb0b3acf..49374a5b3 100644 --- a/src/common/caching.c +++ b/src/common/caching.c @@ -5,6 +5,8 @@ #define FF_CACHE_VALUE_EXTENSION "ffcv" #define FF_CACHE_SPLIT_EXTENSION "ffcs" +#define FF_CACHE_EXTENSION_STRUCT "ffcs2" + static void getCacheFilePath(FFinstance* instance, const char* moduleName, const char* extension, FFstrbuf* buffer) { ffStrbufAppend(buffer, &instance->state.cacheDir); @@ -22,7 +24,7 @@ static void readCacheFile(FFinstance* instance, const char* moduleName, const ch FFstrbuf path; ffStrbufInitA(&path, 64); getCacheFilePath(instance, moduleName, extension, &path); - ffAppendFileContent(path.chars, buffer); + ffAppendFileBuffer(path.chars, buffer); ffStrbufDestroy(&path); } diff --git a/src/common/io.c b/src/common/io.c index 016346d59..62e220e92 100644 --- a/src/common/io.c +++ b/src/common/io.c @@ -22,14 +22,10 @@ static void createSubfolders(const char* fileName) ffStrbufDestroy(&path); } -bool ffWriteFDData(int fd, size_t dataSize, const void* data) -{ - return write(fd, data, dataSize) != -1; -} bool ffWriteFDBuffer(int fd, const FFstrbuf* content) { - return ffWriteFDData(fd, content->length, content->chars); + return write(fd, content->chars, content->length) != -1; } bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data) @@ -46,7 +42,7 @@ bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data) return false; } - bool ret = ffWriteFDData(fd, dataSize, data); + bool ret = write(fd, data, dataSize) != -1; close(fd); @@ -58,7 +54,7 @@ bool ffWriteFileBuffer(const char* fileName, const FFstrbuf* buffer) return ffWriteFileData(fileName, buffer->length, buffer->chars); } -void ffAppendFDContent(int fd, FFstrbuf* buffer) +bool ffAppendFDBuffer(int fd, FFstrbuf* buffer) { ssize_t readed = 0; @@ -82,24 +78,40 @@ void ffAppendFDContent(int fd, FFstrbuf* buffer) ffStrbufTrimRight(buffer, '\n'); ffStrbufTrimRight(buffer, ' '); + + return readed >= 0; } -bool ffAppendFileContent(const char* fileName, FFstrbuf* buffer) +ssize_t ffGetFileData(const char* fileName, size_t dataSize, void* data) +{ + int fd = open(fileName, O_RDONLY); + if(fd == -1) + return -1; + + ssize_t readed = read(fd, data, dataSize); + + close(fd); + + return readed; +} + +bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer) { int fd = open(fileName, O_RDONLY); if(fd == -1) return false; - ffAppendFDContent(fd, buffer); + bool ret = ffAppendFDBuffer(fd, buffer); close(fd); - return true; + + return ret; } -bool ffGetFileContent(const char* fileName, FFstrbuf* buffer) +bool ffGetFileBuffer(const char* fileName, FFstrbuf* buffer) { ffStrbufClear(buffer); - return ffAppendFileContent(fileName, buffer); + return ffAppendFileBuffer(fileName, buffer); } // Not thread safe! diff --git a/src/common/processing.c b/src/common/processing.c index 4a00fd533..95c3dcb6d 100644 --- a/src/common/processing.c +++ b/src/common/processing.c @@ -29,6 +29,6 @@ void ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[]) //Parent close(pipes[1]); waitpid(childPid, NULL, 0); - ffAppendFDContent(pipes[0], buffer); + ffAppendFDBuffer(pipes[0], buffer); close(pipes[0]); } diff --git a/src/detection/displayserver/wmde.c b/src/detection/displayserver/wmde.c index 6c4069a14..83b5dbd5e 100644 --- a/src/detection/displayserver/wmde.c +++ b/src/detection/displayserver/wmde.c @@ -337,7 +337,7 @@ static void getFromProcDir(const FFinstance* instance, FFDisplayServerResult* re //Don't check for processes not owend by the current user. ffStrbufAppendS(&procPath, "/loginuid"); - ffGetFileContent(procPath.chars, &loginuid); + ffGetFileBuffer(procPath.chars, &loginuid); if(ffStrbufComp(&userID, &loginuid) != 0) { ffStrbufSubstrBefore(&procPath, procPathLength); @@ -348,7 +348,7 @@ static void getFromProcDir(const FFinstance* instance, FFDisplayServerResult* re //We check the cmdline for the process name, because it is not trimmed. ffStrbufAppendS(&procPath, "/cmdline"); - ffGetFileContent(procPath.chars, &processName); + ffGetFileBuffer(procPath.chars, &processName); ffStrbufSubstrBeforeFirstC(&processName, '\0'); //Trim the arguments ffStrbufSubstrAfterLastC(&processName, '/'); diff --git a/src/detection/temps.c b/src/detection/temps.c index 4a6928768..c97f7c97a 100644 --- a/src/detection/temps.c +++ b/src/detection/temps.c @@ -32,7 +32,7 @@ static bool parseHwmonDir(FFstrbuf* dir, FFTempValue* value) continue; ffStrbufAppendS(dir, dirent->d_name); - ffGetFileContent(dir->chars, &valueString); + ffGetFileBuffer(dir->chars, &valueString); ffStrbufSubstrBefore(dir, dirLength); //ffStrbufToDouble() returns NaN if the string couldn't be parsed @@ -51,11 +51,11 @@ static bool parseHwmonDir(FFstrbuf* dir, FFTempValue* value) return false; ffStrbufAppendS(dir, "name"); - ffGetFileContent(dir->chars, &value->name); + ffGetFileBuffer(dir->chars, &value->name); ffStrbufSubstrBefore(dir, dirLength); ffStrbufAppendS(dir, "device/class"); - ffGetFileContent(dir->chars, &value->deviceClass); + ffGetFileBuffer(dir->chars, &value->deviceClass); ffStrbufSubstrBefore(dir, dirLength); return value->name.length > 0 || value->deviceClass.length > 0; diff --git a/src/detection/terminalShell.c b/src/detection/terminalShell.c index eaa7ae5da..4ac7b6dfa 100644 --- a/src/detection/terminalShell.c +++ b/src/detection/terminalShell.c @@ -21,7 +21,7 @@ static void getProcessInformation(const char* pid, FFstrbuf* processName, FFstrb ffStrbufAppendS(&cmdlineFilePath, pid); ffStrbufAppendS(&cmdlineFilePath, "/cmdline"); - ffGetFileContent(cmdlineFilePath.chars, exe); + ffGetFileBuffer(cmdlineFilePath.chars, exe); ffStrbufSubstrBeforeFirstC(exe, '\0'); //Trim the arguments ffStrbufTrimLeft(exe, '-'); //Happens in TTY diff --git a/src/fastfetch.h b/src/fastfetch.h index 31acd1e2c..b3848577f 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -413,14 +413,14 @@ void ffListFeatures(); void ffStartDetectionThreads(FFinstance* instance); //common/io.c -bool ffWriteFDData(int fd, size_t dataSize, const void* data); bool ffWriteFDBuffer(int fd, const FFstrbuf* content); bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data); bool ffWriteFileBuffer(const char* fileName, const FFstrbuf* buffer); -void ffAppendFDContent(int fd, FFstrbuf* buffer); -bool ffAppendFileContent(const char* fileName, FFstrbuf* buffer); //returns true if open() succeeds. This is used to differentiate between and -bool ffGetFileContent(const char* fileName, FFstrbuf* buffer); +bool ffAppendFDBuffer(int fd, FFstrbuf* buffer); +ssize_t ffGetFileData(const char* fileName, size_t dataSize, void* data); +bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer); +bool ffGetFileBuffer(const char* fileName, FFstrbuf* buffer); bool ffFileExists(const char* fileName, mode_t mode); void ffSuppressIO(bool suppress); // Not thread safe! diff --git a/src/logo/image/image.c b/src/logo/image/image.c index bf0aacbc3..d731b01a7 100644 --- a/src/logo/image/image.c +++ b/src/logo/image/image.c @@ -375,7 +375,7 @@ static void readCachedStrbuf(FFLogoRequestData* requestData, FFstrbuf* result, c { uint32_t cacheDirLength = requestData->cacheDir.length; ffStrbufAppendS(&requestData->cacheDir, cacheFileName); - ffAppendFileContent(requestData->cacheDir.chars, result); + ffAppendFileBuffer(requestData->cacheDir.chars, result); ffStrbufSubstrBefore(&requestData->cacheDir, cacheDirLength); } diff --git a/src/logo/logo.c b/src/logo/logo.c index 0bb5aae41..05faa7af8 100644 --- a/src/logo/logo.c +++ b/src/logo/logo.c @@ -249,7 +249,7 @@ static bool logoPrintFileIfExists(FFinstance* instance, bool doColorReplacement) FFstrbuf content; ffStrbufInitA(&content, 2047); - if(!ffAppendFileContent(instance->config.logoSource.chars, &content)) + if(!ffAppendFileBuffer(instance->config.logoSource.chars, &content)) { ffStrbufDestroy(&content); return false; diff --git a/src/modules/battery.c b/src/modules/battery.c index 1ef5e131a..4af4a310c 100644 --- a/src/modules/battery.c +++ b/src/modules/battery.c @@ -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); } diff --git a/src/modules/cpu.c b/src/modules/cpu.c index 20625d99a..36eb5f561 100644 --- a/src/modules/cpu.c +++ b/src/modules/cpu.c @@ -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); diff --git a/src/modules/host.c b/src/modules/host.c index 8f3979524..5992faa05 100644 --- a/src/modules/host.c +++ b/src/modules/host.c @@ -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")) {