#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/swap.h>
+#include <sys/sysinfo.h>
#include <unistd.h>
#include <linux/fs.h>
}
unsigned long long hw_memory() {
- FILE* handle = NULL;
- char line[STRING_SIZE];
+ struct sysinfo si;
- unsigned long long memory = 0;
-
- /* Calculate amount of memory in machine */
- if ((handle = fopen("/proc/meminfo", "r"))) {
- while (fgets(line, sizeof(line), handle)) {
- if (!sscanf (line, "MemTotal: %llu kB", &memory)) {
- memory = 0;
- }
- }
-
- fclose(handle);
- }
+ int r = sysinfo(&si);
+ if (r < 0)
+ return 0;
- return memory * 1024;
+ return si.totalram;
}
static int hw_zero_out_device(const char* path, int bytes) {