summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Stapelberg <michael@stapelberg.de>2011-01-06 18:22:46 +0100
committerMichael Stapelberg <michael@stapelberg.de>2011-01-06 18:22:46 +0100
commit4ec02bea7bbe534ef4b610bc63d1694bf0823174 (patch)
tree7135bc4c587523c1d43aafc832c4df0716c9061f /src
parent7507a3d03c59d4a94829040f591f4ea08f8f840a (diff)
implement the 'path' option for cpu temperature
Diffstat (limited to 'src')
-rw-r--r--src/print_cpu_temperature.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/print_cpu_temperature.c b/src/print_cpu_temperature.c
index d524f0b..84f78e0 100644
--- a/src/print_cpu_temperature.c
+++ b/src/print_cpu_temperature.c
@@ -21,11 +21,14 @@ static char *thermal_zone;
* returns the temperature in degree celcius.
*
*/
-void print_cpu_temperature_info(int zone, const char *format) {
+void print_cpu_temperature_info(int zone, const char *path, const char *format) {
const char *walk;
static char buf[16];
- asprintf(&thermal_zone, THERMAL_ZONE, zone);
+ if (path == NULL) {
+ asprintf(&thermal_zone, THERMAL_ZONE, zone);
+ path = thermal_zone;
+ }
for (walk = format; *walk != '\0'; walk++) {
if (*walk != '%') {
@@ -36,8 +39,8 @@ void print_cpu_temperature_info(int zone, const char *format) {
if (BEGINS_WITH(walk+1, "degrees")) {
#if defined(LINUX)
long int temp;
- if (!slurp(thermal_zone, buf, sizeof(buf)))
- die("Could not open \"%s\"\n", thermal_zone);
+ if (!slurp(path, buf, sizeof(buf)))
+ die("Could not open \"%s\"\n", path);
temp = strtol(buf, NULL, 10);
if (temp == LONG_MIN || temp == LONG_MAX || temp <= 0)
(void)printf("?");
@@ -46,7 +49,7 @@ void print_cpu_temperature_info(int zone, const char *format) {
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
int sysctl_rslt;
size_t sysctl_size = sizeof(sysctl_rslt);
- if (sysctlbyname(thermal_zone, &sysctl_rslt, &sysctl_size, NULL, 0)) {
+ if (sysctlbyname(path, &sysctl_rslt, &sysctl_size, NULL, 0)) {
(void)printf("No thermal zone found");
return;
}