GetMem fix
This commit is contained in:
parent
14fce9786e
commit
8a789784cc
34
src/fetch.c
34
src/fetch.c
@ -5,11 +5,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#if defined(__LINUX__) || defined(__ANDROID__)
|
||||
#include <sys/sysinfo.h>
|
||||
#endif
|
||||
|
||||
#include "fetch.h"
|
||||
#include "config.h"
|
||||
#include "logo.h"
|
||||
@ -124,17 +119,20 @@ int GetUser(const char *title, const FETCH fetch) {
|
||||
}
|
||||
|
||||
int GetUptime(const char *title, const FETCH fetch) {
|
||||
int hours = 0;
|
||||
int mins = 0;
|
||||
|
||||
#ifdef CLOCK
|
||||
struct timespec uptime;
|
||||
clock_gettime(CLOCK, &uptime);
|
||||
|
||||
hours = uptime.tv_sec / 3600;
|
||||
mins = (uptime.tv_sec / 60) - (uptime.tv_sec / 3600 * 60);
|
||||
int days = uptime.tv_sec / 86400;
|
||||
int hours = uptime.tv_sec / 3600;
|
||||
int mins = (uptime.tv_sec / 60) - (uptime.tv_sec / 3600 * 60);
|
||||
|
||||
if (days > 0)
|
||||
printf("%s%s%s%dd %dh %dm", fetch.color, title, fetch.font_color, days, hours, mins);
|
||||
|
||||
else
|
||||
printf("%s%s%s%dh %dm", fetch.color, title, fetch.font_color, hours, mins);
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
@ -182,17 +180,17 @@ int GetPkg(const char *title, const FETCH fetch) {
|
||||
}
|
||||
|
||||
int GetMem(const char *title, const FETCH fetch) {
|
||||
#if defined(__LINUX__) || defined(__ANDROID__)
|
||||
struct sysinfo sinfo;
|
||||
if (sysinfo(&sinfo) < 0)
|
||||
unsigned int free = 0, cache = 0, total = 0, unused;
|
||||
UNUSED(unused);
|
||||
|
||||
FILE *fp = fopen("/proc/meminfo", "r");
|
||||
if (fp == NULL)
|
||||
return 1;
|
||||
|
||||
printf("%s%s%s%lumb / %lumb", fetch.color, title, fetch.font_color, sinfo.freeram / 1048576, sinfo.totalram / 1048576);
|
||||
fscanf(fp, "MemTotal: %u kB\nMemFree: %u kB\nMemAvailable: %u kB\nBuffers: %u kB\nCached: %u kB", &total, &free, &unused, &unused, &cache);
|
||||
|
||||
#else
|
||||
printf("%s%s%s0mb / 0mb", fetch.color, title, fetch.font_color);
|
||||
|
||||
#endif
|
||||
printf("%s%s%s%umb / %umb", fetch.color, title, fetch.font_color, (free + cache) / 1024, total / 1024);
|
||||
fclose(fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -23,6 +23,6 @@ int main(void) {
|
||||
for (; i < fetch.logo_size; i++)
|
||||
printf("%s\n", fetch.logo[i]);
|
||||
|
||||
printf("\033[0m\n");
|
||||
printf("\033[0m");
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user