Mercurial > hg > svcore
comparison system/System.cpp @ 169:603991c63ff6
...
author | Chris Cannam |
---|---|
date | Mon, 25 Sep 2006 20:32:44 +0000 |
parents | 04baa690f90d |
children | b23eea68357e |
comparison
equal
deleted
inserted
replaced
168:04baa690f90d | 169:603991c63ff6 |
---|---|
13 COPYING included with this distribution for more information. | 13 COPYING included with this distribution for more information. |
14 */ | 14 */ |
15 | 15 |
16 #include "System.h" | 16 #include "System.h" |
17 | 17 |
18 #include <QFile> | |
19 #include <QTextStream> | |
20 #include <QStringList> | 18 #include <QStringList> |
21 #include <QString> | 19 #include <QString> |
22 | 20 |
23 #ifndef _WIN32 | 21 #ifndef _WIN32 |
24 #include <signal.h> | 22 #include <signal.h> |
77 } | 75 } |
78 | 76 |
79 int | 77 int |
80 GetRealMemoryMBAvailable() | 78 GetRealMemoryMBAvailable() |
81 { | 79 { |
82 // ugh | 80 FILE *meminfo = fopen("/proc/meminfo", "r"); |
83 QFile meminfo("/proc/meminfo"); | 81 if (!meminfo) return -1; |
84 if (meminfo.open(QFile::ReadOnly)) { | 82 |
85 std::cerr << "opened meminfo" << std::endl; | 83 char buf[256]; |
86 QTextStream in(&meminfo); | 84 while (!feof(meminfo)) { |
87 while (!in.atEnd()) { | 85 fgets(buf, 256, meminfo); |
88 QString line = in.readLine(256); | 86 if (strncmp(buf, "MemFree:", 8)) { |
89 std::cerr << "read: \"" << line.toStdString() << "\"" << std::endl; | 87 fclose(meminfo); |
90 if (line.startsWith("MemFree:")) { | 88 QString line = QString(buf).trimmed(); |
91 QStringList elements = line.split(' ', QString::SkipEmptyParts); | 89 QStringList elements = line.split(' ', QString::SkipEmptyParts); |
92 QString unit = "kB"; | 90 QString unit = "kB"; |
93 if (elements.size() > 2) unit = elements[2]; | 91 if (elements.size() > 2) unit = elements[2]; |
94 int size = elements[1].toInt(); | 92 int size = elements[1].toInt(); |
95 std::cerr << "have size \"" << size << "\", unit \"" | 93 // std::cerr << "have size \"" << size << "\", unit \"" |
96 << unit.toStdString() << "\"" << std::endl; | 94 // << unit.toStdString() << "\"" << std::endl; |
97 if (unit.toLower() == "gb") return size * 1024; | 95 if (unit.toLower() == "gb") return size * 1024; |
98 if (unit.toLower() == "mb") return size; | 96 if (unit.toLower() == "mb") return size; |
99 if (unit.toLower() == "kb") return size / 1024; | 97 if (unit.toLower() == "kb") return size / 1024; |
100 return size / 1048576; | 98 return size / 1048576; |
101 } | |
102 } | 99 } |
103 } | 100 } |
101 fclose(meminfo); | |
104 return -1; | 102 return -1; |
105 } | 103 } |
106 | 104 |
107 int | 105 int |
108 GetDiscSpaceMBAvailable(const char *path) | 106 GetDiscSpaceMBAvailable(const char *path) |