summaryrefslogtreecommitdiff
path: root/src/stmemory.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stmemory.c')
-rw-r--r--src/stmemory.c31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/stmemory.c b/src/stmemory.c
index 3553563..4f1435a 100644
--- a/src/stmemory.c
+++ b/src/stmemory.c
@@ -16,32 +16,27 @@
#include <stdio.h>
-// TODO: Memory hogs on left click using signals
+#include "../lib/util.h"
int
main(void)
{
- FILE *meminfo;
- char buff[100];
- long memtotal, memavail = 0;
+ FILE *fp;
+ char line[256];
+ long total, free;
- meminfo = fopen("/proc/meminfo", "r");
+ if (!(fp = fopen("/proc/meminfo", "r")))
+ die("failed to open: /proc/meminfo");
- if (meminfo == NULL) {
- puts("Error opening file");
- return 1;
- }
+ fgets(line, sizeof(line), fp);
+ sscanf(line + 9, "%ld", &total);
- fgets(buff, sizeof(buff), meminfo);
- sscanf(buff + 9, "%ld", &memtotal);
+ fgets(line, sizeof(line), fp);
+ fgets(line, sizeof(line), fp);
+ sscanf(line + 13, "%ld", &free);
- fgets(buff, sizeof(buff), meminfo);
- fgets(buff, sizeof(buff), meminfo);
- sscanf(buff + 13, "%ld", &memavail);
-
- printf("%ldMB", (memtotal - memavail) / 1024 );
-
- fclose(meminfo);
+ printf("%ldMB", (total - free) / 1024 );
+ fclose(fp);
return 0;
}