]> git.sur5r.net Git - i3/i3status/blobdiff - src/print_disk_info.c
Adding optional configuration option to "print_disk_info".
[i3/i3status] / src / print_disk_info.c
index ef028bdf3bd710c8d4ae9896fec35744be28c524..4ed2f22c7bfee30a44db1ed520fc5e26eac628be 100644 (file)
@@ -108,7 +108,7 @@ static bool below_threshold(struct statvfs buf, const char *prefix_type, const c
  * human readable manner.
  *
  */
-void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const char *format, const char *prefix_type, const char *threshold_type, const double low_threshold) {
+void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const char *format, const char *format_not_mounted, const char *prefix_type, const char *threshold_type, const double low_threshold) {
         const char *walk;
         char *outwalk = buffer;
         bool colorful_output = false;
@@ -125,25 +125,25 @@ void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const ch
 
         if (statvfs(path, &buf) == -1)
                 return;
-#endif
 
-        FILE *mntentfile = setmntent("/etc/mtab", "r");
-        struct mntent *m;
-        bool found = false;
+        if (format_not_mounted != NULL) {
+                FILE *mntentfile = setmntent("/etc/mtab", "r");
+                struct mntent *m;
+                bool found = false;
 
-        while (NULL != (m = getmntent(mntentfile))) {
-                if (strcmp(m->mnt_dir, path) == 0) {
-                        found = true;
-                        break;
+                while (NULL != (m = getmntent(mntentfile))) {
+                        if (strcmp(m->mnt_dir, path) == 0) {
+                                found = true;
+                                break;
+                        }
                 }
-        }
-        endmntent(mntentfile);
+                endmntent(mntentfile);
 
-        if (!found) {
-                *buffer = '\0';
-                OUTPUT_FULL_TEXT(buffer);
-                return;
+                if (!found) {
+                        format = format_not_mounted;
+                }
         }
+#endif
 
         if (low_threshold > 0 && below_threshold(buf, prefix_type, threshold_type, low_threshold)) {
                 START_COLOR("color_bad");