20#include <sys/sysctl.h>
36 size_t max_size = 0) {
39 int* name =
const_cast<int*
>(mib.data());
41 const int* name = mib.data();
43 u_int namelen = mib.size();
44 size_t size = max_size;
47 "sysctl failed: {}",
StrError(errno));
50 std::vector<T> out(
size /
sizeof(T));
55 size = out.size() *
sizeof(T);
56 CF_EXPECTF(sysctl(name, namelen, out.data(), &
size,
nullptr, 0) == 0,
57 "sysctl failed: {}",
StrError(errno));
58 out.resize(
size /
sizeof(T));
#define CF_EXPECTF(RESULT, MSG,...)
Definition: expect.h:187
uint32_t size
Definition: io.h:2
Definition: alloc_driver.h:21
std::string StrError()
Definition: strerror.cc:26
Result< std::vector< T > > ReadSysctl(std::span< const int > mib, size_t max_size=0)
Definition: proc_file_utils_sysctl.h:35
tl::expected< T, StackTraceError< E > > Result
Definition: result_type.h:30