Fix crash if key bindings specified in profile cannot be found. Improve
[personal-kdebase.git] / apps / kinfocenter / memory / memory_linux.cpp
blob9ca7594a20974dc6c5af2c385c486f2081dfbc17
1 #include <sys/sysinfo.h>
2 #include <unistd.h>
3 #include <stdlib.h>
4 #include <QFile>
6 void KCMMemory::fetchValues()
8 struct sysinfo info;
10 sysinfo(&info); /* Get Information from system... */
12 /*
13 * The sysinfo.mem_unit member variable is not available in older 2.4 kernels.
14 * If you have troubles compiling this code, set mem_unit to "1".
17 const int mem_unit = info.mem_unit;
19 memoryInfos[TOTAL_MEM] = MEMORY(info.totalram) * mem_unit; // total physical memory (without swaps)
20 memoryInfos[FREE_MEM] = MEMORY(info.freeram) * mem_unit; // total free physical memory (without swaps)
21 memoryInfos[SHARED_MEM] = MEMORY(info.sharedram) * mem_unit;
22 memoryInfos[BUFFER_MEM] = MEMORY(info.bufferram) * mem_unit;
23 memoryInfos[SWAP_MEM] = MEMORY(info.totalswap) * mem_unit; // total size of all swap-partitions
24 memoryInfos[FREESWAP_MEM] = MEMORY(info.freeswap) * mem_unit; // free memory in swap-partitions
26 QFile file("/proc/meminfo");
27 if (file.open(QIODevice::ReadOnly)) {
28 char buf[512];
29 while (file.readLine(buf, sizeof(buf) - 1) > 0) {
30 if (strncmp(buf,"Cached:",7)==0) {
31 unsigned long v;
32 v = strtoul(&buf[7],NULL,10);
33 memoryInfos[CACHED_MEM] = MEMORY(v) * 1024; // Cached memory in RAM
34 break;
37 file.close();