My slstatus configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

48 lines
961 B

  1. /* See LICENSE file for copyright and license details. */
  2. #include <stddef.h>
  3. #include "../util.h"
  4. #if defined(__linux__)
  5. const char *
  6. temp(const char *file)
  7. {
  8. int temp;
  9. return (pscanf(file, "%d", &temp) == 1) ?
  10. bprintf("%d", temp / 1000) : NULL;
  11. }
  12. #elif defined(__OpenBSD__)
  13. #include <errno.h>
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <sys/time.h> /* before <sys/sensors.h> for struct timeval */
  17. #include <sys/sensors.h>
  18. #include <sys/sysctl.h>
  19. const char *
  20. temp(const char *null)
  21. {
  22. int mib[5];
  23. size_t size;
  24. struct sensor temp;
  25. mib[0] = CTL_HW;
  26. mib[1] = HW_SENSORS;
  27. mib[2] = 0; /* cpu0 */
  28. mib[3] = SENSOR_TEMP;
  29. mib[4] = 0; /* temp0 */
  30. size = sizeof(temp);
  31. if (sysctl(mib, 5, &temp, &size, NULL, 0) < 0) {
  32. fprintf(stderr, "sysctl 'SENSOR_TEMP': %s\n",
  33. strerror(errno));
  34. return NULL;
  35. }
  36. /* kelvin to celsius */
  37. return bprintf("%d", (temp.value - 273150000) / 1000000);
  38. }
  39. #endif