Skip to content

Instantly share code, notes, and snippets.

@su8
Last active September 1, 2018 18:57
Show Gist options
  • Save su8/2cdb401ba39c1fd00562c022337074cc to your computer and use it in GitHub Desktop.
Save su8/2cdb401ba39c1fd00562c022337074cc to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/sysctl.h>
int main(void) {
u_int val[3] = {0};
char buf[256] = {""};
size_t len = sizeof(val);
size_t len2 = sizeof(buf);
if (0 != (sysctlbyname("dev.cpu.0.temperature", &val, &len, NULL, 0))) {
if (0 != (sysctlbyname("dev.aibs.0.%desc", buf, &len2, NULL, 0))) {
puts("failed!");
return EXIT_FAILURE;
}
}
if (0 != (strcmp(buf, "")))
printf("%s\n", buf);
else
printf("%lu\n", (unsigned long)val[0]);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment