mirror of
https://github.com/rad4day/Waybar.git
synced 2025-07-19 09:22:43 +02:00
memory: port parseMeminfo to BSDs
This commit is contained in:
20
src/modules/memory/linux.cpp
Normal file
20
src/modules/memory/linux.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "modules/memory.hpp"
|
||||
|
||||
void waybar::modules::Memory::parseMeminfo() {
|
||||
const std::string data_dir_ = "/proc/meminfo";
|
||||
std::ifstream info(data_dir_);
|
||||
if (!info.is_open()) {
|
||||
throw std::runtime_error("Can't open " + data_dir_);
|
||||
}
|
||||
std::string line;
|
||||
while (getline(info, line)) {
|
||||
auto posDelim = line.find(':');
|
||||
if (posDelim == std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string name = line.substr(0, posDelim);
|
||||
int64_t value = std::stol(line.substr(posDelim + 1));
|
||||
meminfo_[name] = value;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user