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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. if(pscanf(file, "%d", &temp) != 1) {
  10. return NULL;
  11. }
  12. return bprintf("%d", temp / 1000);
  13. }
  14. #elif defined(__OpenBSD__)
  15. #include <errno.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <sys/time.h> /* before <sys/sensors.h> for struct timeval */
  19. #include <sys/sensors.h>
  20. #include <sys/sysctl.h>
  21. const char *
  22. temp(const char *unused)
  23. {
  24. int mib[5];
  25. size_t size;
  26. struct sensor temp;
  27. mib[0] = CTL_HW;
  28. mib[1] = HW_SENSORS;
  29. mib[2] = 0; /* cpu0 */
  30. mib[3] = SENSOR_TEMP;
  31. mib[4] = 0; /* temp0 */
  32. size = sizeof(temp);
  33. if (sysctl(mib, 5, &temp, &size, NULL, 0) < 0) {
  34. warn("sysctl 'SENSOR_TEMP':");
  35. return NULL;
  36. }
  37. /* kelvin to celsius */
  38. return bprintf("%d", (temp.value - 273150000) / 1000000);
  39. }
  40. #endif