]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - src/install+setup/install/hw.c
installer: Make function to determine the amount of system memory.
[ipfire-2.x.git] / src / install+setup / install / hw.c
index 1fca9fdfa9d3d2dee5c471f517ebdcfd5d9aef4f..f26c63836f62dcc564b7d54e741a25479de25c70 100644 (file)
@@ -315,3 +315,23 @@ struct hw_destination* hw_make_destination(int part_type, struct hw_disk** disks
 
        return dest;
 }
+
+unsigned long long hw_memory() {
+       FILE* handle = NULL;
+       char line[STRING_SIZE];
+
+       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);
+       }
+
+       return memory * 1024;
+}