My slstatus configuration
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

temperature.c 882 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* See LICENSE file for copyright and license details. */
  2. #include <errno.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #if defined(__OpenBSD__)
  6. #include <sys/sysctl.h>
  7. #include <sys/time.h>
  8. #include <sys/sensors.h>
  9. #endif
  10. #include "../util.h"
  11. #if defined(__linux__)
  12. const char *
  13. temp(const char *file)
  14. {
  15. int temp;
  16. return (pscanf(file, "%d", &temp) == 1) ?
  17. bprintf("%d", temp / 1000) : NULL;
  18. }
  19. #elif defined(__OpenBSD__)
  20. const char *
  21. temp(const char *null)
  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) == -1) {
  33. fprintf(stderr, "sysctl 'SENSOR_TEMP': %s\n", strerror(errno));
  34. return NULL;
  35. }
  36. return bprintf("%d", (temp.value - 273150000) / 1000000); /* kelvin to celsius */
  37. }
  38. #endif