Oops. Forgot the usleep.c file.
[oweals/busybox.git] / free.c
diff --git a/free.c b/free.c
index 36d357522e16265dede3763e3218a7f5ae3e95b0..78a36fe9a412690c78ef666e3c2a166a387afb71 100644 (file)
--- a/free.c
+++ b/free.c
@@ -1,3 +1,4 @@
+/* vi: set sw=4 ts=4: */
 /*
  * Mini free implementation for busybox
  *
 
 #include "internal.h"
 #include <stdio.h>
+#include <sys/sysinfo.h>
 
-
-#if ! defined BB_FEATURE_USE_PROCFS
-#error Sorry, I depend on the /proc filesystem right now.
-#endif
-
+#define DIVISOR        1024
 extern int free_main(int argc, char **argv)
 {
-    char* cmd[] = { "cat", "/proc/meminfo", "\0" };
-    exit(cat_main( 3, cmd));
+       struct sysinfo info;
+       sysinfo(&info);
+       info.totalram/=DIVISOR;
+       info.freeram/=DIVISOR;
+       info.totalswap/=DIVISOR;
+       info.freeswap/=DIVISOR;
+       info.sharedram/=DIVISOR;
+       info.bufferram/=DIVISOR;
+
+
+       printf("%6s%13s%13s%13s%13s%13s\n", "", "total", "used", "free", 
+                       "shared", "buffers");
+
+       printf("%6s%13ld%13ld%13ld%13ld%13ld\n", "Mem:", info.totalram, 
+                       info.totalram-info.freeram, info.freeram, 
+                       info.sharedram, info.bufferram);
+
+       printf("%6s%13ld%13ld%13ld\n", "Swap:", info.totalswap,
+                       info.totalswap-info.freeswap, info.freeswap);
+
+       printf("%6s%13ld%13ld%13ld\n", "Total:", info.totalram+info.totalswap,
+                       (info.totalram-info.freeram)+(info.totalswap-info.freeswap),
+                       info.freeram+info.freeswap);
+       exit(TRUE);
 }