rename funcs, move get_val
This commit is contained in:
19
src/sys.cpp
19
src/sys.cpp
@@ -7,6 +7,17 @@
|
||||
#include <sys.hpp>
|
||||
#include <utils.hpp>
|
||||
|
||||
int getVal(std::string_view target, std::string_view content) {
|
||||
int result = -1;
|
||||
std::size_t start = content.find(target);
|
||||
if (start != std::string::npos) {
|
||||
int begin = start + target.length();
|
||||
std::size_t end = content.find("kB", start);
|
||||
result = std::strtol(content.substr(begin, end - begin).data(), NULL, 10);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void sys::getTimeDate(TimeDate* td) {
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto local = std::chrono::current_zone()->to_local(now);
|
||||
@@ -17,9 +28,9 @@ void sys::getTimeDate(TimeDate* td) {
|
||||
}
|
||||
|
||||
void sys::getRam(Memory* mem) {
|
||||
auto content = readFile("/proc/meminfo", 128); // file is longer than that but its all we need
|
||||
mem->free = get_val("MemAvailable:", content);
|
||||
mem->total = get_val("MemTotal:", content);
|
||||
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);
|
||||
mem->used = mem->total - mem->free;
|
||||
}
|
||||
|
||||
@@ -62,7 +73,7 @@ void sys::detectHwmon(sysSensors* s, const std::string& platform) {
|
||||
}
|
||||
|
||||
void sys::updateSensors(sysSensors* s) {
|
||||
if(s->hwmon.length() < 1)
|
||||
if (s->hwmon.length() < 1)
|
||||
return;
|
||||
static char buf[8];
|
||||
fastReadNum(s->hwmon + "/fan2_input", s->fan_speed[0]);
|
||||
|
||||
Reference in New Issue
Block a user