mirror of
https://github.com/aristocratos/btop.git
synced 2024-09-29 22:51: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() {
|
double system_uptime() {
|
||||||
string upstr;
|
string upstr;
|
||||||
ifstream pread(Shared::procPath / "uptime");
|
ifstream pread(Shared::procPath / "uptime");
|
||||||
|
if (pread.good()) {
|
||||||
|
try {
|
||||||
getline(pread, upstr, ' ');
|
getline(pread, upstr, ' ');
|
||||||
pread.close();
|
pread.close();
|
||||||
return stod(upstr);
|
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