diff --git a/CMakeLists.txt b/CMakeLists.txt index 9887610ef..d1fa527ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,8 +19,7 @@ set(PROJECT_VERSION "r${GIT_REV_LIST}.${GIT_REV_PARSE}") include (${CMAKE_ROOT}/Modules/FindX11.cmake) -#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -march=native -O3 -pipe -fno-plt") # for testing -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -march=native -O3 -pipe -fno-plt") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -march=native -O3 -pipe -fno-plt") # for testing configure_file(src/fastfetch_config.h.in fastfetch_config.h) include_directories(${PROJECT_BINARY_DIR}) diff --git a/src/cpu.c b/src/cpu.c index 66437dde3..bcb2d8943 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -35,8 +35,6 @@ void ffPrintCPU(FFstate* state) char value[1024]; sprintf(value, "%s (%i) @ %.9gGHz", name, get_nprocs(), ghz); - ffSaveCachedValue(state, "CPU", value); - - ffPrintLogoAndKey(state, "CPU"); - puts(value); + + ffPrintAndSaveCachedValue(state, "CPU", value); } \ No newline at end of file diff --git a/src/fastfetch.c b/src/fastfetch.c index c94a4a910..3e9e28214 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -138,21 +138,26 @@ bool ffPrintCachedValue(FFstate* state, const char* key) return false; char value[1024]; - if(read(fd, value, sizeof(value) - 1) < 1) + + ssize_t readed = read(fd, value, sizeof(value) - 1); + if(readed < 1) return false; - value[1023] = '\n'; //Ensure that we end with a newline, even when we didn't fully read the file - close(fd); + value[readed] = '\0'; //Somehow read doesn't alway do this + ffPrintLogoAndKey(state, key); puts(value); return true; } -void ffSaveCachedValue(FFstate* state, const char* key, const char* value) +void ffPrintAndSaveCachedValue(FFstate* state, const char* key, const char* value) { + ffPrintLogoAndKey(state, key); + puts(value); + char fileName[256]; getCacheFileName(state, key, fileName); diff --git a/src/fastfetch.h b/src/fastfetch.h index 403e5203a..66c44c0cb 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -56,7 +56,7 @@ void ffParsePropFileHome(FFstate* state, const char* relativeFile, const char* r void ffPrintGtkPretty(const char* gtk2, const char* gtk3, const char* gtk4); void ffPrintError(FFstate* state, const char* key, const char* message); bool ffPrintCachedValue(FFstate* state, const char* key); -void ffSaveCachedValue(FFstate* state, const char* key, const char* value); +void ffPrintAndSaveCachedValue(FFstate* state, const char* key, const char* value); void ffLoadLogoSet(FFstate* state, const char* logo); void ffLoadLogo(FFstate* state); diff --git a/src/gpu.c b/src/gpu.c index 11466ff7c..537145c93 100644 --- a/src/gpu.c +++ b/src/gpu.c @@ -31,10 +31,7 @@ static void handleGPU(FFstate* state, struct pci_access* pacc, struct pci_dev* d strcat(gpu, name); - ffSaveCachedValue(state, key, gpu); - - ffPrintLogoAndKey(state, key); - puts(gpu); + ffPrintAndSaveCachedValue(state, key, gpu); } void ffPrintGPU(FFstate* state) diff --git a/src/host.c b/src/host.c index e6c26606a..e8fff1cf9 100644 --- a/src/host.c +++ b/src/host.c @@ -31,8 +31,5 @@ void ffPrintHost(FFstate* state) fclose(versionFile); } - ffSaveCachedValue(state, "Host", host); - - ffPrintLogoAndKey(state, "Host"); - puts(host); + ffPrintAndSaveCachedValue(state, "Host", host); } \ No newline at end of file diff --git a/src/locale.c b/src/locale.c index 0f9639cb9..5016c349d 100644 --- a/src/locale.c +++ b/src/locale.c @@ -13,8 +13,5 @@ void ffPrintLocale(FFstate* state) return; } - ffSaveCachedValue(state, "Locale", locale); - - ffPrintLogoAndKey(state, "Locale"); - puts(locale); + ffPrintAndSaveCachedValue(state, "Locale", locale); } \ No newline at end of file diff --git a/src/os.c b/src/os.c index 9713ead88..262fdc22b 100644 --- a/src/os.c +++ b/src/os.c @@ -16,8 +16,5 @@ void ffPrintOS(FFstate* state) char os[1024]; sprintf(os, "%s %s", name, state->utsname.machine); - ffSaveCachedValue(state, "OS", os); - - ffPrintLogoAndKey(state, "OS"); - puts(os); + ffPrintAndSaveCachedValue(state, "OS", os); } \ No newline at end of file diff --git a/src/resolution.c b/src/resolution.c index d01313177..cf198885a 100644 --- a/src/resolution.c +++ b/src/resolution.c @@ -13,8 +13,5 @@ void ffPrintResolution(FFstate* state) char resolution[1024]; sprintf(resolution, "%ix%i", screen->width, screen->height); - ffSaveCachedValue(state, "Resolution", resolution); - - ffPrintLogoAndKey(state, "Resolution"); - puts(resolution); + ffPrintAndSaveCachedValue(state, "Resolution", resolution); } \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 750eb901b..1287ee79d 100644 --- a/src/shell.c +++ b/src/shell.c @@ -21,8 +21,5 @@ void ffPrintShell(FFstate* state) else if(shellName[0] == '/') ++shellName; - ffSaveCachedValue(state, "Shell", shellName); - - ffPrintLogoAndKey(state, "Shell"); - puts(shellName); + ffPrintAndSaveCachedValue(state, "Shell", shellName); } \ No newline at end of file