Better file structure and build system
[sysstatus.git] / src / status / fan.c
diff --git a/src/status/fan.c b/src/status/fan.c
new file mode 100644 (file)
index 0000000..0e7cfdf
--- /dev/null
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "status/fan.h"
+#include "tools.h"
+
+
+void status_fan(char *title, char *sysfile)
+{
+  char stline[16];
+  ssize_t stlen;
+
+  stlen = fileRead(stline, sizeof(stline), sysfile);
+  if (stlen <= 0) {
+    return;
+  }
+
+  // Read a valid value? Sometimes we get garbage from sysfs...
+  if (stlen > 5) {
+    printf(" ^fg(red)%sERROR ", title);
+    return;
+  }
+
+  fputs(" ^fg(#CCCCCC)", stdout);
+  fputs(title, stdout);
+  fwrite(stline, 1, stlen - 1, stdout);
+  fputs(" rpm ", stdout);
+}