use std::array instead of c-style bufs
This commit is contained in:
14
src/sys.cpp
14
src/sys.cpp
@@ -30,8 +30,8 @@ void sys::getTimeDate(TimeDate* td) {
|
||||
}
|
||||
|
||||
void sys::getRam(Memory* mem) {
|
||||
static char buf[128]; // file is longer but we only need first 128 chars
|
||||
utils::readFile("/proc/meminfo", buf, sizeof(buf));
|
||||
static std::array<char, 128> buf; // file is longer but we only need first 128 chars
|
||||
utils::readFile("/proc/meminfo", buf);
|
||||
mem->free = getVal("MemAvailable:", std::string_view(buf));
|
||||
mem->total = getVal("MemTotal:", std::string_view(buf)); // shouldn't really update this on each loop
|
||||
mem->used = mem->total - mem->free;
|
||||
@@ -46,15 +46,15 @@ void sys::getDisk(Disk* disk) {
|
||||
}
|
||||
|
||||
void sys::getNetwork(Network* net, const std::string& device) {
|
||||
struct _net {
|
||||
struct Network {
|
||||
std::chrono::time_point<std::chrono::steady_clock> ts;
|
||||
uint64_t rx = 0;
|
||||
uint64_t tx = 0;
|
||||
};
|
||||
|
||||
static char buf[32];
|
||||
static _net prev;
|
||||
_net current;
|
||||
static std::array<char, 32> buf;
|
||||
static Network prev;
|
||||
Network current;
|
||||
|
||||
current.ts = std::chrono::steady_clock::now();
|
||||
utils::fastReadNum("/sys/class/net/" + device + "/statistics/rx_bytes", buf, current.rx);
|
||||
@@ -78,7 +78,7 @@ void sys::detectHwmon(sysSensors* s, const std::string& platform) {
|
||||
void sys::updateSensors(sysSensors* s) {
|
||||
if (s->hwmon.empty())
|
||||
return;
|
||||
static char buf[8];
|
||||
static std::array<char, 8> buf;
|
||||
utils::fastReadNum(s->hwmon + "/fan2_input", buf, s->fan_speed[0]);
|
||||
utils::fastReadNum(s->hwmon + "/fan7_input", buf, s->fan_speed[1]);
|
||||
utils::fastReadNum<1000>(s->hwmon + "/temp5_input", buf, s->t_sensor);
|
||||
|
||||
Reference in New Issue
Block a user