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.
 
 
 
 

50 line
927 B

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