use std::array instead of c-style bufs

This commit is contained in:
2026-01-02 13:44:01 +01:00
parent 27350122b2
commit 0eb401cdcc
3 changed files with 21 additions and 18 deletions

View File

@@ -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);