]> git.sur5r.net Git - i3/i3status/blobdiff - src/print_cpu_temperature.c
fix ethernet speed display for 100 Gbit/s cards
[i3/i3status] / src / print_cpu_temperature.c
index 57cb1148fbc85fee35c65825a55911a154ede05d..01744a14fac57293768b163bd545fa6f0229904f 100644 (file)
@@ -1,4 +1,5 @@
 // vim:ts=4:sw=4:expandtab
+#include <config.h>
 #include <stdlib.h>
 #include <limits.h>
 #include <glob.h>
@@ -13,7 +14,7 @@
 #include <err.h>
 #include <sys/types.h>
 #include <sys/sysctl.h>
-#define TZ_ZEROC 2732
+#define TZ_ZEROC 2731
 #define TZ_KELVTOC(x) (((x)-TZ_ZEROC) / 10), abs(((x)-TZ_ZEROC) % 10)
 #define TZ_AVG(x) ((x)-TZ_ZEROC) / 10
 #endif
@@ -52,7 +53,7 @@ typedef struct temperature_s {
 #define ERROR_CODE 1
 
 static int read_temperature(char *thermal_zone, temperature_t *temperature) {
-#if defined(LINUX)
+#if defined(__linux__)
     static char buf[16];
     long int temp;
 
@@ -112,7 +113,7 @@ static int read_temperature(char *thermal_zone, temperature_t *temperature) {
         /* 'path' is the node within the full path (defaults to acpitz0). */
         if (BEGINS_WITH(sensordev.xname, thermal_zone)) {
             mib[3] = SENSOR_TEMP;
-            /* Limit to temo0, but should retrieve from a full path... */
+            /* Limit to temp0, but should retrieve from a full path... */
             for (numt = 0; numt < 1 /*sensordev.maxnumt[SENSOR_TEMP]*/; numt++) {
                 mib[4] = numt;
                 if (sysctl(mib, 5, &sensor, &slen, NULL, 0) == -1) {
@@ -205,7 +206,7 @@ error_netbsd1:
 
 /*
  * Reads the CPU temperature from /sys/class/thermal/thermal_zone%d/temp (or
- * the user provided path) and returns the temperature in degree celcius.
+ * the user provided path) and returns the temperature in degree celsius.
  *
  */
 void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const char *path, const char *format, const char *format_above_threshold, int max_threshold) {
@@ -216,12 +217,14 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const
     bool colorful_output = false;
     char *thermal_zone;
     temperature_t temperature;
+    temperature.raw_value = 0;
+    sprintf(temperature.formatted_value, "%.2f", 0.0);
 
     if (path == NULL)
         asprintf(&thermal_zone, THERMAL_ZONE, zone);
     else {
         static glob_t globbuf;
-        if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0)
+        if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) != 0)
             die("glob() failed\n");
         if (globbuf.gl_pathc == 0) {
             /* No glob matches, the specified path does not contain a wildcard. */
@@ -248,11 +251,13 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const
     for (walk = selected_format; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
-        if (BEGINS_WITH(walk + 1, "degrees")) {
+
+        } else if (BEGINS_WITH(walk + 1, "degrees")) {
             outwalk += sprintf(outwalk, "%s", temperature.formatted_value);
             walk += strlen("degrees");
+
+        } else {
+            *(outwalk++) = '%';
         }
     }