Xinqi Bao's Git

Implement fmt_human_2() and fmt_human_10()
[slstatus.git] / components / netspeeds.c
index 32e78d6..f0f7455 100644 (file)
                if (pscanf(path, "%llu", &rxbytes) != 1) {
                        return NULL;
                }
+               if (oldrxbytes == 0) {
+                       return NULL;
+               }
 
-               return oldrxbytes ? fmt_scaled((rxbytes - oldrxbytes) *
-                                              1000 / interval) : NULL;
+               return fmt_human_2((rxbytes - oldrxbytes) *
+                                  1000 / interval, "B/s");
        }
 
        const char *
                if (pscanf(path, "%llu", &txbytes) != 1) {
                        return NULL;
                }
+               if (oldtxbytes == 0) {
+                       return NULL;
+               }
 
-               return oldtxbytes ? fmt_scaled((txbytes - oldtxbytes) *
-                                              1000 / interval) : NULL;
+               return fmt_human_2((txbytes - oldtxbytes) *
+                                  1000 / interval, "B/s");
        }
 #elif defined(__OpenBSD__)
        #include <string.h>
                        warn("reading 'if_data' failed");
                        return NULL;
                }
+               if (oldrxbytes == 0) {
+                       return NULL;
+               }
 
-               return oldrxbytes ? fmt_scaled((rxbytes - oldrxbytes) *
-                                              1000 / interval) : NULL;
+               return fmt_human_2((rxbytes - oldrxbytes) *
+                                  1000 / interval, "B/s");
        }
 
        const char *
                        warn("reading 'if_data' failed");
                        return NULL;
                }
+               if (oldtxbytes == 0) {
+                       return NULL;
+               }
 
-               return oldtxbytes ? fmt_scaled((txbytes - oldtxbytes) *
-                                              1000 / interval) : NULL;
+               return fmt_human_2((txbytes - oldtxbytes) *
+                                  1000 / interval, "B/s");
        }
 #endif