+ return 0;
+}
+
+/*
+ * Reads the CPU temperature from /sys/class/thermal/thermal_zone%d/temp (or
+ * 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) {
+ char *outwalk = buffer;
+#ifdef THERMAL_ZONE
+ const char *selected_format = format;
+ const char *walk;
+ 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)
+ die("glob() failed\n");
+ if (globbuf.gl_pathc == 0) {
+ /* No glob matches, the specified path does not contain a wildcard. */
+ asprintf(&thermal_zone, path, zone);
+ } else {
+ /* glob matched, we take the first match and ignore the others */
+ asprintf(&thermal_zone, "%s", globbuf.gl_pathv[0]);
+ }
+ globfree(&globbuf);
+ }
+
+ INSTANCE(thermal_zone);
+
+ if (read_temperature(thermal_zone, &temperature) != 0)
+ goto error;
+
+ if (temperature.raw_value >= max_threshold) {
+ START_COLOR("color_bad");
+ colorful_output = true;
+ if (format_above_threshold != NULL)
+ selected_format = format_above_threshold;
+ }
+
+ for (walk = selected_format; *walk != '\0'; walk++) {
+ if (*walk != '%') {
+ *(outwalk++) = *walk;
+
+ } else if (BEGINS_WITH(walk + 1, "degrees")) {
+ outwalk += sprintf(outwalk, "%s", temperature.formatted_value);
+ walk += strlen("degrees");
+
+ } else {
+ *(outwalk++) = '%';