Reindent and restyle
[sysstatus.git] / statuses / temp.c
index 83e1ac9171c93119dcd242bc9b4f9057c819651d..f2cece80197589a228df2af6d4d845c2f1120f13 100644 (file)
@@ -5,27 +5,30 @@
 
 void status_temp(char *title, char *sysfile)
 {
-       char stline[16];
-       int stfile;
-       size_t stlen;
+  char stline[16];
+  int stfile;
+  ssize_t stlen;
 
-       stfile = open(sysfile, 0);
-       if (stfile != -1)
-       {
-               stlen = read(stfile, stline, sizeof(stline));
-               close(stfile);
-               if (stlen >= 6 && stlen <= 7)
-               {
-                       fputs(" ^fg(#FF33FF)", stdout);
-                       fputs(title, stdout);
-                       fwrite(stline, 1, stlen - 4, stdout);
-                       /*
-                       fputs(".", stdout);
-                       fwrite(&stline[stlen - 3], 1, 1, stdout);
-                       */
-                       fputs("°C ", stdout);
-               }
-               else
-                       printf(" ^fg(red)%sERROR ", title);
-       }
+  stlen = fileRead(stline, sizeof(stline), sysfile);
+  if (stlen <= 0) {
+    return;
+  }
+
+  /*
+   * Read a valid value?
+   * Sometimes we get garbage from sysfs...
+   */
+  if (stlen < 6 || stlen > 7) {
+    printf(" ^fg(red)%sERROR ", title);
+    return;
+  }
+
+  fputs(" ^fg(#FF33FF)", stdout);
+  fputs(title, stdout);
+  fwrite(stline, 1, stlen - 4, stdout);
+  /*
+  fputs(".", stdout);
+  fwrite(&stline[stlen - 3], 1, 1, stdout);
+  */
+  fputs("°C ", stdout);
 }