My slstatus configuration
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

temperature.c 925 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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°C", 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 *unused)
  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. warn("sysctl 'SENSOR_TEMP':");
  33. return NULL;
  34. }
  35. /* kelvin to celsius */
  36. return bprintf("%d°C", (temp.value - 273150000) / 1000000);
  37. }
  38. #endif