diff --git a/include/utils.hpp b/include/utils.hpp index e858294..e658850 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -7,8 +7,8 @@ #define FILL_CHAR ' ' -// wrapper around readFile func so we can avoid readFileToStr and reuse one buffer, this should be faster and less bug prone? -#define fastReadNum(path, val) readFile(path, buf, sizeof(buf)); val = strtoll(buf, NULL, 10) +// wrapper around readFile func +#define fastReadNum(path, val) readFile(path, buf, sizeof(buf)); val = std::strtoll(buf, NULL, 10) enum JUST { RIGHT, @@ -21,7 +21,6 @@ inline std::string pNum(auto num, uint8_t decs = 0) { return std::format("{:.{}f std::string pad(std::string s, uint8_t len, JUST j = JUST::RIGHT); std::string center(std::string str, uint8_t len); std::string pBytes(double bytes, bool isKbytes = false); -std::string readFileToStr(std::string path, size_t trim = 4096); ssize_t readFile(std::string path, char* buffer, size_t maxlen); ssize_t readFile(const char* path, char* buffer, size_t maxlen); std::string getFirstDir(std::string_view path); diff --git a/src/cpu.cpp b/src/cpu.cpp index c5f850b..ee81f78 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -16,7 +16,8 @@ void detectHwmon(cpuSensors* target, std::string pci) { log(LOG::ERR, "cpu::detectHwmon", "NO CPU HWMON KERNEL MODULE DETECTED"); return; } - target->zenpower = readFileToStr((target->hwmon + "/name"), 128) == "zenpower"; + + target->zenpower = false; // we were using readFileToStr to figure this out, we dont f/w it anymore, find another way (see if hwmon/in1_input exists?) log(LOG::INF, "cpu::detectHwmon", "Detected module \"{}\" in path \"{}\"", target->zenpower ? "zenpower" : "k10temp", target->hwmon); } diff --git a/src/sys.cpp b/src/sys.cpp index c4ef488..a5eb729 100644 --- a/src/sys.cpp +++ b/src/sys.cpp @@ -28,9 +28,10 @@ void sys::getTimeDate(TimeDate* td) { } void sys::getRam(Memory* mem) { - auto content = readFileToStr("/proc/meminfo", 128); // file is longer than that but its all we need - mem->free = getVal("MemAvailable:", content); - mem->total = getVal("MemTotal:", content); + static char buf[128]; // file is longer but we only need first 128 chars + readFile("/proc/meminfo", buf, sizeof(buf)); + mem->free = getVal("MemAvailable:", std::string_view(buf)); + mem->total = getVal("MemTotal:", std::string_view(buf)); mem->used = mem->total - mem->free; } diff --git a/src/utils.cpp b/src/utils.cpp index 4241a7d..ad233d4 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -59,15 +59,7 @@ ssize_t readFile(std::string path, char* buffer, size_t maxlen) { return readFile(path.c_str(), buffer, maxlen); } -std::string readFileToStr(std::string path, size_t trim) { - char* buf = new char[trim + 2]; - ssize_t len = readFile(path, buf, trim + 2); - std::string out(buf); - delete[] buf; - if (!len) return "0"; - return out.substr(0, len - 1); -} - +/* finds first dir in path and returns it*/ std::string getFirstDir(std::string_view path) { for (const auto& entry : std::filesystem::directory_iterator(path)) return entry.path();