#include #include #include void * asysctl(const int *oids, size_t oidlen, size_t *lenp) { void *data; if (sysctl(oids, oidlen, NULL, lenp, NULL, 0) == -1) return NULL; if (*lenp == 0) return NULL; retry: data = malloc(*lenp); if (data == NULL) return NULL; if (sysctl(oids, oidlen, data, lenp, NULL, 0) == -1) { free(data); if ((errno == ENOMEM) && (*lenp < SIZE_MAX)) goto retry; return NULL; } return data; }