mirror of
https://github.com/aristocratos/btop.git
synced 2024-09-28 22:21:35 +02:00
Added: ifstream check and try-catch for stod() in Tools::system_uptime()
This commit is contained in:
parent
5ae05f0333
commit
528df4d84f
@ -1611,8 +1611,15 @@ namespace Tools {
|
||||
double system_uptime() {
|
||||
string upstr;
|
||||
ifstream pread(Shared::procPath / "uptime");
|
||||
if (pread.good()) {
|
||||
try {
|
||||
getline(pread, upstr, ' ');
|
||||
pread.close();
|
||||
return stod(upstr);
|
||||
}
|
||||
catch (const std::invalid_argument&) {}
|
||||
catch (const std::out_of_range&) {}
|
||||
}
|
||||
throw std::runtime_error("Failed get uptime from from " + (string)Shared::procPath + "/uptime");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user