| 159 | }; |
| 160 | |
| 161 | Value read_value(const fs::path& path) { |
| 162 | std::error_code ec; |
| 163 | const bool there = fs::exists(path, ec); |
| 164 | if (ec) return {Value::bad, 0}; |
| 165 | if (!there) return {}; |
| 166 | std::ifstream file(path); |
| 167 | if (!file) return {Value::bad, 0}; |
| 168 | char buf[64]; |
| 169 | file.read(buf, sizeof buf); |
| 170 | if (file.bad()) return {Value::bad, 0}; |
| 171 | size_t len = (size_t) file.gcount(); |
| 172 | if (len == sizeof buf) return {Value::bad, 0}; |
| 173 | while (len > 0 && (buf[len - 1] == '\n' || buf[len - 1] == '\r' || buf[len - 1] == ' ' || buf[len - 1] == '\t')) --len; |
| 174 | if (len == 0) return {Value::bad, 0}; |
| 175 | if (len == 3 && std::string(buf, 3) == "max") return {Value::max, 0}; |
| 176 | Value v{Value::number, 0}; |
| 177 | const auto parsed = std::from_chars(buf, buf + len, v.n); |
| 178 | if (parsed.ec != std::errc{} || parsed.ptr != buf + len) return {Value::bad, 0}; |
| 179 | return v; |
| 180 | } |
| 181 | |
| 182 | // The reclaimable file cache of one group, from its memory.stat, in the two forms the guard uses |
| 183 | // (cache_credit_from_stat in the header has the rules). A memory.stat that is missing gives no credit - not an |
no test coverage detected