From 5f71ef71da82adbb658688f04ca5034824fedf6d Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Sun, 16 May 2021 15:10:15 +0200 Subject: [PATCH] small syntactic changes --- src/common/io.c | 10 +++++----- src/fastfetch.c | 2 +- src/modules/gpu.c | 5 +++-- src/modules/packages.c | 12 ++++++------ src/modules/resolution_x11.c | 5 +++-- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/common/io.c b/src/common/io.c index f8c7f2909..35f64fd23 100644 --- a/src/common/io.c +++ b/src/common/io.c @@ -292,23 +292,24 @@ void ffCacheClose(FFcache* cache) bool ffParsePropFile(const char* fileName, const char* start, FFstrbuf* buffer) { - char* line = NULL; - size_t len = 0; - FILE* file = fopen(fileName, "r"); if(file == NULL) return false; // handle errors in higher functions + char* line = NULL; + size_t len = 0; + while (getline(&line, &len, file) != -1) { if(ffGetPropValue(line, start, buffer)) break; } - fclose(file); if(line != NULL) free(line); + fclose(file); + return true; } @@ -329,7 +330,6 @@ bool ffParsePropFileHome(FFinstance* instance, const char* relativeFile, const c bool ffParsePropFileConfig(FFinstance* instance, const char* relativeFile, const char* start, FFstrbuf* buffer) { - uint32_t bufferLengthStart = buffer->length; bool foundAFile = false; diff --git a/src/fastfetch.c b/src/fastfetch.c index 27fe7d259..707968a73 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -64,7 +64,7 @@ static inline void printHelp() " -l , --logo : sets the shown logo. Also changes the main color accordingly\n" " --color-logo : if set to false, the logo will be black / white\n" "\n" - "Format options: Provide the format string for custom output (+)\n" + "Format options: Provide the format string for custom output. Use fastfetch --help *-format for specific help.\n" " --os-format \n" " --host-format \n" " --kernel-format \n" diff --git a/src/modules/gpu.c b/src/modules/gpu.c index 2af8e4ed3..524a5e09c 100644 --- a/src/modules/gpu.c +++ b/src/modules/gpu.c @@ -54,10 +54,11 @@ void ffPrintGPU(FFinstance* instance) if(ffPrintFromCache(instance, FF_GPU_MODULE_NAME, &instance->config.gpuKey, &instance->config.gpuFormat, FF_GPU_NUM_FORMAT_ARGS)) return; - void* pci = dlopen(instance->config.libPCI.length == 0 ? "libpci.so" : instance->config.libPCI.chars, RTLD_LAZY); + const char* pciLibName = instance->config.libPCI.length == 0 ? "libpci.so" : instance->config.libPCI.chars; + void* pci = dlopen(pciLibName, RTLD_LAZY); if(pci == NULL) { - ffPrintError(instance, FF_GPU_MODULE_NAME, 0, &instance->config.gpuKey, &instance->config.gpuFormat, FF_GPU_NUM_FORMAT_ARGS, "dlopen(\"libpci.so\", RTLD_LAZY) == NULL"); + ffPrintError(instance, FF_GPU_MODULE_NAME, 0, &instance->config.gpuKey, &instance->config.gpuFormat, FF_GPU_NUM_FORMAT_ARGS, "dlopen(\"%s\", RTLD_LAZY) == NULL", pciLibName); return; } diff --git a/src/modules/packages.c b/src/modules/packages.c index fc1a9d169..5ce2d8649 100644 --- a/src/modules/packages.c +++ b/src/modules/packages.c @@ -6,15 +6,15 @@ #define FF_PACKAGES_MODULE_NAME "Packages" #define FF_PACKAGES_NUM_FORMAT_ARGS 7 -static uint32_t getNumElements(const char* dirname, unsigned char type) { - uint32_t num_elements = 0; - DIR * dirp; - struct dirent *entry; - - dirp = opendir(dirname); +static uint32_t getNumElements(const char* dirname, unsigned char type) +{ + DIR* dirp = opendir(dirname); if(dirp == NULL) return 0; + uint32_t num_elements = 0; + + struct dirent *entry; while((entry = readdir(dirp)) != NULL) { if(entry->d_type == type) ++num_elements; diff --git a/src/modules/resolution_x11.c b/src/modules/resolution_x11.c index 43648e8ec..28ca0cd02 100644 --- a/src/modules/resolution_x11.c +++ b/src/modules/resolution_x11.c @@ -35,10 +35,11 @@ static void xCloseDisplay(void* library, Display* display) void ffPrintResolutionX11Backend(FFinstance* instance) { - void* x11 = dlopen(instance->config.libX11.length == 0 ? "libX11.so" : instance->config.libX11.chars, RTLD_LAZY); + const char* libX11Name = instance->config.libX11.length == 0 ? "libX11.so" : instance->config.libX11.chars; + void* x11 = dlopen(libX11Name, RTLD_LAZY); if(x11 == NULL) { - ffPrintError(instance, FF_RESOLUTION_MODULE_NAME, 0, &instance->config.resolutionKey, &instance->config.resolutionFormat, FF_RESOLUTION_NUM_FORMAT_ARGS, "dlopen(\"libX11.so\", RTLD_LAZY) == NULL"); + ffPrintError(instance, FF_RESOLUTION_MODULE_NAME, 0, &instance->config.resolutionKey, &instance->config.resolutionFormat, FF_RESOLUTION_NUM_FORMAT_ARGS, "dlopen(\"%s\", RTLD_LAZY) == NULL", libX11Name); return; }