Xinqi Bao's Git

wifi: Fix coding style
[slstatus.git] / components / ram.c
index 5611022..57081d2 100644 (file)
                       NULL;
        }
 #elif defined(__OpenBSD__)
-       #include <sys/types.h>
-       #include <sys/sysctl.h>
        #include <stdlib.h>
+       #include <sys/sysctl.h>
+       #include <sys/types.h>
        #include <unistd.h>
 
+       #define LOG1024         10
+       #define pagetok(size, pageshift) ((size) << (pageshift - LOG1024))
+
        inline int
        load_uvmexp(struct uvmexp *uvmexp)
        {
@@ -79,8 +82,7 @@
 
                if (load_uvmexp(&uvmexp)) {
                        free_pages = uvmexp.npages - uvmexp.active;
-                       free = (double) (free_pages * uvmexp.pagesize) / 1024 /
-                              1024 / 1024;
+                       free = (float)(pagetok(free_pages, uvmexp.pageshift)) / 1024 / 1024;
                        return bprintf("%f", free);
                }
 
                float total;
 
                if (load_uvmexp(&uvmexp)) {
-                       total = (double) (uvmexp.npages * uvmexp.pagesize) /
-                               1024 / 1024 / 1024;
+                       total = (float)(pagetok(uvmexp.npages, uvmexp.pageshift)) / 1024 / 1024;
                        return bprintf("%f", total);
                }
 
                float used;
 
                if (load_uvmexp(&uvmexp)) {
-                       used = (double) (uvmexp.active * uvmexp.pagesize) /
-                              1024 / 1024 / 1024;
+                       used = (float)(pagetok(uvmexp.active, uvmexp.pageshift)) / 1024 / 1024;
                        return bprintf("%f", used);
                }