Switch to side-by-side view

--- a/src/pathut.cpp
+++ b/src/pathut.cpp
@@ -23,13 +23,17 @@
 #endif
 
 #include <stdio.h>
+#include <math.h>
+#include <errno.h>
+
 #ifdef _WIN32
 #include "dirent.h"
 #include "safefcntl.h"
 #include "safeunistd.h"
 #include "safewindows.h"
 #include "safesysstat.h"
-#else
+
+#else // Not windows ->
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/param.h>
@@ -37,24 +41,9 @@
 #include <sys/file.h>
 #include <sys/stat.h>
 #include <dirent.h>
-#endif
-#include <math.h>
-#include <errno.h>
+#include <sys/statvfs.h>
 #include <sys/types.h>
 
-// Let's include all files where statfs can be defined and hope for no
-// conflict...
-#ifdef HAVE_SYS_MOUNT_H
-#include <sys/mount.h>
-#endif
-#ifdef HAVE_SYS_STATFS_H
-#include <sys/statfs.h>
-#endif
-#ifdef HAVE_SYS_STATVFS_H
-#include <sys/statvfs.h>
-#endif
-#ifdef HAVE_SYS_VFS_H
-#include <sys/vfs.h>
 #endif
 
 #include <cstdlib>
@@ -101,8 +90,6 @@
 }
 #endif
 
-#if defined(HAVE_SYS_MOUNT_H) || defined(HAVE_SYS_STATFS_H) || \
-    defined(HAVE_SYS_STATVFS_H) || defined(HAVE_SYS_VFS_H) || defined(_WIN32)
 bool fsocc(const string& path, int *pc, long long *avmbs)
 {
     static const int FSOCC_MB = 1024 * 1024;
@@ -120,36 +107,29 @@
         *avmbs = int(totalbytes.QuadPart / FSOCC_MB);
     }
     return true;
-#else
-#ifdef sun
+#else // not windows ->
+
     struct statvfs buf;
     if (statvfs(path.c_str(), &buf) != 0) {
         return false;
     }
-#else
-    struct statfs buf;
-    if (statfs(path.c_str(), &buf) != 0) {
-        return false;
-    }
-#endif
-
-    // used blocks
-    double fpc = 0.0;
-#define FSOCC_USED (double(buf.f_blocks - buf.f_bfree))
-#define FSOCC_TOTAVAIL (FSOCC_USED + double(buf.f_bavail))
-    if (FSOCC_TOTAVAIL > 0) {
-        fpc = 100.0 * FSOCC_USED / FSOCC_TOTAVAIL;
-    }
+
     if (pc) {
+        double fsocc_used = double(buf.f_blocks - buf.f_bfree);
+        double fsocc_totavail = fsocc_used + double(buf.f_bavail);
+        double fpc = 100.0;
+        if (fsocc_totavail > 0) {
+            fpc = 100.0 * fsocc_used / fsocc_totavail;
+        }
         *pc = int(fpc);
     }
     if (avmbs) {
         *avmbs = 0;
         if (buf.f_bsize > 0) {
-            int ratio = buf.f_bsize > FSOCC_MB ? buf.f_bsize / FSOCC_MB :
-                        FSOCC_MB / buf.f_bsize;
-
-            *avmbs = buf.f_bsize > FSOCC_MB ?
+            int ratio = buf.f_frsize > FSOCC_MB ? buf.f_frsize / FSOCC_MB :
+                        FSOCC_MB / buf.f_frsize;
+
+            *avmbs = buf.f_frsize > FSOCC_MB ?
                      ((long long)buf.f_bavail) * ratio :
                      ((long long)buf.f_bavail) / ratio;
         }
@@ -157,7 +137,7 @@
     return true;
 #endif
 }
-#endif // we have found an appropriate include file
+
 
 string path_PATHsep()
 {
@@ -1026,7 +1006,7 @@
     return 0;
 #endif
 
-#if 1
+#if 0
     if (argc != 1) {
         cerr << "Usage: trpathut url" << endl;
         exit(1);
@@ -1038,6 +1018,26 @@
     return 0;
 #endif
 
+#if 1
+    if (argc != 1) {
+        cerr << "Usage: trpathut path" << endl;
+        exit(1);
+    }
+    string path = *argv++;
+    argc--;
+
+    int pc;
+    long long avmbs;
+    if (fsocc(path, &pc, &avmbs)) {
+        cout << "Percent occup " << pc << " avmbs " << avmbs << endl;
+        return 0;
+    } else {
+        cerr << "fsocc failed\n";
+        return 1;
+    }
+#endif
+
+
 
 }