remove duplicated size_str function from sync.c

Sun, 31 Aug 2025 14:37:41 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 31 Aug 2025 14:37:41 +0200
changeset 876
9c2e229b05f9
parent 875
3b9ac2dd757d
child 877
b60487c3ec36

remove duplicated size_str function from sync.c

dav/sync.c file | annotate | diff | comparison | revisions
--- a/dav/sync.c	Sun Aug 31 14:32:55 2025 +0200
+++ b/dav/sync.c	Sun Aug 31 14:37:41 2025 +0200
@@ -5060,73 +5060,6 @@
     return 0;
 }
 
-
-// TODO: remove code dup (main.c ls_size_str)
-static char* size_str(uint64_t size) {
-    char *str = malloc(16);
-    
-    if(size < 0x400) {
-        snprintf(str, 16, "%" PRIu64 " bytes", size);
-    } else if(size < 0x100000) {
-        float s = (float)size/0x400;
-        int diff = (s*100 - (int)s*100);
-        if(diff > 90) {
-            diff = 0;
-            s += 0.10f;
-        }
-        if(size < 0x2800 && diff != 0) {
-            // size < 10 KiB
-            snprintf(str, 16, "%.1f KiB", s);
-        } else {
-            snprintf(str, 16, "%.0f KiB", s);
-        }
-    } else if(size < 0x40000000) {
-        float s = (float)size/0x100000;
-        int diff = (s*100 - (int)s*100);
-        if(diff > 90) {
-            diff = 0;
-            s += 0.10f;
-        }
-        if(size < 0xa00000 && diff != 0) {
-            // size < 10 MiB
-            snprintf(str, 16, "%.1f MiB", s);
-        } else {
-            size /= 0x100000;
-            snprintf(str, 16, "%.0f MiB", s);
-        }
-    } else if(size < 0x1000000000ULL) {
-        float s = (float)size/0x40000000;
-        int diff = (s*100 - (int)s*100);
-        if(diff > 90) {
-            diff = 0;
-            s += 0.10f;
-        }
-        if(size < 0x280000000 && diff != 0) {
-            // size < 10 GiB
-            snprintf(str, 16, "%.1f GiB", s);
-        } else {
-            size /= 0x40000000;
-            snprintf(str, 16, "%.0f GiB", s);
-        }
-    } else {
-        size /= 1024;
-        float s = (float)size/0x40000000;
-        int diff = (s*100 - (int)s*100);
-        if(diff > 90) {
-            diff = 0;
-            s += 0.10f;
-        }
-        if(size < 0x280000000 && diff != 0) {
-            // size < 10 TiB
-            snprintf(str, 16, "%.1f TiB", s);
-        } else {
-            size /= 0x40000000;
-            snprintf(str, 16, "%.0f TiB", s);
-        }
-    }
-    return str;
-}
-
 void print_resource_version(DavResource *res, char *name) {
     time_t now = res->lastmodified;
     struct tm *date = gmtime(&now);
@@ -5305,7 +5238,7 @@
     
     log_printf("path: %s\n", syncdir->trash);
     log_printf("%d %s\n", count, count == 1 ? "file" : "files");
-    char *sizestr = size_str(trashsize);
+    char *sizestr = util_size_str(FALSE, trashsize);
     log_printf("%s\n", sizestr);
     free(sizestr);
     

mercurial