]> git.sur5r.net Git - i3/i3status/blobdiff - src/print_disk_info.c
Unit testing in Travis (#170)
[i3/i3status] / src / print_disk_info.c
index 7fd47b9d916ded11ef2352de930ef41fe12c9ac9..624a8e2f2c2431d3074c36c0957909a8ca9dcc07 100644 (file)
@@ -7,9 +7,10 @@
 #include <sys/stat.h>
 #include <sys/statvfs.h>
 #include <sys/types.h>
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || (__OpenBSD__) || defined(__DragonFly__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || (__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
 #include <sys/param.h>
 #include <sys/mount.h>
+#elif defined(__NetBSD__)
 #else
 #include <mntent.h>
 #endif
@@ -59,7 +60,7 @@ static int print_bytes_human(char *outwalk, uint64_t bytes, const char *prefix_t
  * Determines whether remaining bytes are below given threshold.
  *
  */
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__DragonFly__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
 static bool below_threshold(struct statfs buf, const char *prefix_type, const char *threshold_type, const double low_threshold) {
 #else
 static bool below_threshold(struct statvfs buf, const char *prefix_type, const char *threshold_type, const double low_threshold) {
@@ -116,19 +117,28 @@ void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const ch
 
     INSTANCE(path);
 
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__DragonFly__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
     struct statfs buf;
 
     if (statfs(path, &buf) == -1)
         return;
+#elif defined(__NetBSD__)
+    struct statvfs buf;
+
+    if (statvfs(path, &buf) == -1)
+        return;
 #else
     struct statvfs buf;
 
+    if (format_not_mounted == NULL) {
+        format_not_mounted = "";
+    }
+
     if (statvfs(path, &buf) == -1) {
         /* If statvfs errors, e.g., due to the path not existing,
          * we use the format for a not mounted device. */
         format = format_not_mounted;
-    } else if (format_not_mounted != NULL) {
+    } else {
         FILE *mntentfile = setmntent("/etc/mtab", "r");
         struct mntent *m;
         bool found = false;
@@ -179,22 +189,22 @@ void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const ch
         }
 
         if (BEGINS_WITH(walk + 1, "percentage_free")) {
-            outwalk += sprintf(outwalk, "%.01f%%", 100.0 * (double)buf.f_bfree / (double)buf.f_blocks);
+            outwalk += sprintf(outwalk, "%.01f%s", 100.0 * (double)buf.f_bfree / (double)buf.f_blocks, pct_mark);
             walk += strlen("percentage_free");
         }
 
         if (BEGINS_WITH(walk + 1, "percentage_used_of_avail")) {
-            outwalk += sprintf(outwalk, "%.01f%%", 100.0 * (double)(buf.f_blocks - buf.f_bavail) / (double)buf.f_blocks);
+            outwalk += sprintf(outwalk, "%.01f%s", 100.0 * (double)(buf.f_blocks - buf.f_bavail) / (double)buf.f_blocks, pct_mark);
             walk += strlen("percentage_used_of_avail");
         }
 
         if (BEGINS_WITH(walk + 1, "percentage_used")) {
-            outwalk += sprintf(outwalk, "%.01f%%", 100.0 * (double)(buf.f_blocks - buf.f_bfree) / (double)buf.f_blocks);
+            outwalk += sprintf(outwalk, "%.01f%s", 100.0 * (double)(buf.f_blocks - buf.f_bfree) / (double)buf.f_blocks, pct_mark);
             walk += strlen("percentage_used");
         }
 
         if (BEGINS_WITH(walk + 1, "percentage_avail")) {
-            outwalk += sprintf(outwalk, "%.01f%%", 100.0 * (double)buf.f_bavail / (double)buf.f_blocks);
+            outwalk += sprintf(outwalk, "%.01f%s", 100.0 * (double)buf.f_bavail / (double)buf.f_blocks, pct_mark);
             walk += strlen("percentage_avail");
         }
     }