xdiskusage (1.48-10) 05_xdiskusage.C_support_4.3TB_and_more.patch

Summary

 xdiskusage.C |   50 +++++++++++++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

    
download this patch

Patch contents

Author: Thierry Randrianiriana <randrianiriana@gmail.com>
Description: see bug #555323
--- a/xdiskusage.C
+++ b/xdiskusage.C
@@ -50,23 +50,23 @@
 #include <FL/fl_ask.H>
 #include <FL/math.h>
 
-typedef unsigned long ulong;
+typedef unsigned long long ull;
 
 // turn number of K into user-friendly text:
-const char* formatk(ulong k) {
+const char* formatk(ull k) {
   static char buffer[10];
   if (k >= 1024*1024) sprintf(buffer,"%.4gG",(double)k/(1024*1024));
   else if (k >= 1024) sprintf(buffer,"%.4gM",(double)k/1024);
-  else sprintf(buffer,"%ldK",k);
+  else sprintf(buffer,"%.0fK",(double)k);
   return buffer;
 }
 
 // Holds data read from 'df' for each disk
 struct Disk {
   const char* mount;
-  ulong total;
-  ulong used;
-  ulong avail;
+  ull total;
+  ull used;
+  ull avail;
   Disk* next;
 };
 
@@ -99,9 +99,9 @@
     // ok we found a line with a /xyz at the end:
     Disk* d = new Disk;
     d->mount = strdup(word[n-1]);
-    d->total = strtol(word[n-5],0,10);
-    d->used=strtol(word[n-4],0,10);
-    d->avail=strtol(word[n-3],0,10);
+    d->total = strtoul(word[n-5],0,10);
+    d->used=strtoul(word[n-4],0,10);
+    d->avail=strtoul(word[n-3],0,10);
     *pointer = d;
     d->next = 0;
     pointer = &d->next;
@@ -117,7 +117,7 @@
   for (Disk* d = firstdisk; d; d = d->next) {
     char buf[512];
     int pct;
-    ulong sum = d->used + d->avail;
+    ull sum = d->used + d->avail;
     if (!sum) {
       pct = 0;
     } else {
@@ -161,7 +161,7 @@
   Node* child;
   Node* brother;
   const char* name;
-  ulong size;
+  ull size;
   long ordinal; // sign bit indicates hidden
   bool hidden() const {return ordinal < 0;}
 };
@@ -187,8 +187,8 @@
   OutputWindow(int w, int h, const char* l) : Fl_Window(w,h,l),
     menu_button(0,0,w,h) {box(FL_NO_BOX);}
   void finish_drawn_row();
-  void draw_tree(Node* n, int column, ulong row, double scale, double offset);
-  void print_tree(FILE* f, Node* n, int column, ulong row, double scale, double offset, int W, int H);
+  void draw_tree(Node* n, int column, ull row, double scale, double offset);
+  void print_tree(FILE* f, Node* n, int column, ull row, double scale, double offset, int W, int H);
   void setcurrent(Node*, int);
   void setroot(Node*, int);
 public:
@@ -327,14 +327,14 @@
 // fill in missing totals by adding all sons:
 void fix_tree(Node* n) {
   if (n->size) return;
-  ulong total = 0;
+  ull total = 0;
   for (Node *x = n->child; x; x = x->brother) total += x->size;
   n->size = total;
 }
 
 static long ordinal;
 
-Node* newnode(const char* name, ulong size, Node* parent, Node* & brother) {
+Node* newnode(const char* name, ull size, Node* parent, Node* & brother) {
   Node* n = new Node;
   n->child = n->brother = 0;
   n->name = strdup(name);
@@ -477,8 +477,8 @@
   ordinal = 0;
 
   Node* lastnode[MAXDEPTH];
-  ulong runningtotal;
-  ulong totals[MAXDEPTH];
+  ull runningtotal;
+  ull totals[MAXDEPTH];
   lastnode[0] = root;
   runningtotal = 0;
   totals[0] = 0;
@@ -520,7 +520,7 @@
     char* p = buffer+len;
     if (p > buffer && p[-1] == '\n') p[-1] = 0;
 
-    ulong size = strtoul(buffer, &p, 10);
+    ull size = strtoull(buffer, &p, 10);
     if (!isspace(*p) || p == buffer) {
       if (!*p || *p=='#') continue; // ignore blank lines or comments (?)
       fl_alert("%s:%d: does not look like du output: %s", path, line_no, p);
@@ -555,7 +555,7 @@
 
     if (match == newdepth) {
       Node* p = lastnode[newdepth];
-      ulong t = totals[newdepth]+size;
+      ull t = totals[newdepth]+size;
       p->size = size;
       runningtotal = t;
     } else {
@@ -677,7 +677,7 @@
 }
 
 // Returns first pixel row not drawn into:
-void OutputWindow::draw_tree(Node* n, int column, ulong row, double scale, double offset) {
+void OutputWindow::draw_tree(Node* n, int column, ull row, double scale, double offset) {
   int X = (w()-1)*column/ncols;
   int W = (w()-1)*(column+1)/ncols - X;
   int Y = int(row*scale+offset+.5);
@@ -726,7 +726,7 @@
       if (undrawn_column < X+W+1) undrawn_column = X+W+1;
       if (column+1 < ncols) {
 	// figure out how much is not hidden:
-	ulong hidden = 0;
+	ull hidden = 0;
 	for (Node* c = n->child; c; c = c->brother)
 	  if (c->hidden()) hidden += c->size;
 	if (hidden > 0) {
@@ -811,11 +811,11 @@
     double scale = (double)(h()-1)/current_root->size;
     double offset = 0;
     Node* n = current_root;
-    ulong row = 0;
+    ull row = 0;
     int d = root_depth;
     while (n && d < column) {
       path[d] = n;
-      ulong hidden = 0;
+      ull hidden = 0;
       for (Node* c = n->child; c; c = c->brother)
 	if (c->hidden()) hidden += c->size;
       if (hidden >= n->size) {n = 0; break;}
@@ -1034,7 +1034,7 @@
 ////////////////////////////////////////////////////////////////
 // PostScript output
 
-void OutputWindow::print_tree(FILE*f,Node* n, int column, ulong row,
+void OutputWindow::print_tree(FILE*f,Node* n, int column, ull row,
 			      double scale, double offset,
 			      int bboxw, int bboxh)
 {
@@ -1058,7 +1058,7 @@
     }
     fprintf(f, "\n");
     if (n->child && column+1 < ncols) {
-      ulong hidden = 0;
+      ull hidden = 0;
       for (Node* c = n->child; c; c = c->brother)
 	if (c->hidden()) hidden += c->size;
       if (hidden > 0) {