summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/tools.c
diff options
context:
space:
mode:
authorGuillaume Cottenceau <gc@mandriva.com>2001-02-08 12:49:56 +0000
committerGuillaume Cottenceau <gc@mandriva.com>2001-02-08 12:49:56 +0000
commita0f295c6837be1282b3b7ecca13f08a3c8d99175 (patch)
treed4901671674a9803520fc3a06c42bef0ac006edd /mdk-stage1/tools.c
parentdd565d0c93639079355387546e55a9c615662760 (diff)
downloaddrakx-a0f295c6837be1282b3b7ecca13f08a3c8d99175.tar
drakx-a0f295c6837be1282b3b7ecca13f08a3c8d99175.tar.gz
drakx-a0f295c6837be1282b3b7ecca13f08a3c8d99175.tar.bz2
drakx-a0f295c6837be1282b3b7ecca13f08a3c8d99175.tar.xz
drakx-a0f295c6837be1282b3b7ecca13f08a3c8d99175.zip
better memory detection (from wonderful drakx)
Diffstat (limited to 'mdk-stage1/tools.c')
-rw-r--r--mdk-stage1/tools.c38
1 files changed, 8 insertions, 30 deletions
diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c
index 9acabdb5f..8b2931ad2 100644
--- a/mdk-stage1/tools.c
+++ b/mdk-stage1/tools.c
@@ -183,38 +183,16 @@ int charstar_to_int(char * s)
int total_memory(void)
{
- int fd;
- int i;
- char buf[4096];
- char * memtotal_tag = "MemTotal:";
- int memtotal = 0;
-
- fd = open("/proc/meminfo", O_RDONLY);
- if (fd == -1)
- fatal_error("could not open /proc/meminfo");
-
- i = read(fd, buf, sizeof(buf));
- if (i < 0)
- fatal_error("could not read /proc/meminfo");
-
- close(fd);
- buf[i] = 0;
-
- i = 0;
- while (buf[i] != 0 && strncmp(&buf[i], memtotal_tag, strlen(memtotal_tag)))
- i++;
-
- while (buf[i] != 0 && buf[i] != '\n' && !isdigit(buf[i]))
- i++;
-
- if (buf[i] == 0 || buf[i] == '\n')
- fatal_error("could not read MemTotal");
+ int value;
+ struct stat statr;
+ if (stat("/proc/kcore", &statr))
+ return 0;
- memtotal = charstar_to_int(&(buf[i]));
-
- log_message("%s %d kB", memtotal_tag, memtotal);
+ /* drakx powered: use /proc/kcore and rounds every 4 Mbytes */
+ value = 4 * ((int)((float)statr.st_size / 1024 / 1024 / 4 + 0.5));
+ log_message("Total Memory: %d Mbytes", value);
- return memtotal;
+ return value;
}