+static int mem_size_mb(void)
+{
+ int f;
+ char buf[8192];
+ long int len;
+ const char *pos;
+ long int memsize;
+
+ f = open("/proc/meminfo", O_RDONLY);
+ if (f == -1)
+ return -1;
+
+ len = read(f, buf, sizeof(buf)-1);
+ close(f);
+
+ if (len <= 0)
+ return -1;
+ buf[len] = '\0';
+
+ pos = strstr(buf, "MemTotal: ");
+ if (pos == NULL)
+ return -1;
+
+ if (sscanf(pos, "MemTotal: %ld kB", &memsize) != 1)
+ return -1;
+
+ return memsize / 1024;
+}
+
+static int cpu_count(void)
+{
+ int f;
+ char buf[32768];
+ int len;
+ const char *pos;
+ int count = 0;
+
+ f = open("/proc/stat", O_RDONLY);
+ if (f == -1)
+ return -1;
+
+ len = read(f, buf, sizeof(buf)-1);
+ close(f);
+ if (len <= 0)
+ return -1;
+ buf[len] = '\0';
+
+ pos = strstr(buf, "cpu");
+ if (pos == NULL)
+ return -1;
+
+ while (pos != NULL) {
+ if (strncmp(pos, "cpu", 3) == 0 &&isdigit(pos[3]))
+ count++;
+ pos = strstr(&pos[3], "cpu");
+ }
+
+ if (count == 0)
+ return -1;
+ return count;
+}
+