GetMem fix
This commit is contained in:
parent
14fce9786e
commit
8a789784cc
20
config.h
20
config.h
@ -13,16 +13,16 @@ typedef struct {
|
|||||||
#define PC_CHAR "%"
|
#define PC_CHAR "%"
|
||||||
|
|
||||||
static PARAMETR CONFIG[] = {
|
static PARAMETR CONFIG[] = {
|
||||||
{" OS ", PrintOs},
|
{" OS ", PrintOs},
|
||||||
{" KERNEL ", GetKernel},
|
{" KERNEL ", GetKernel},
|
||||||
{" USER ", GetUser},
|
{" USER ", GetUser},
|
||||||
{" UPTIME ", GetUptime},
|
{" UPTIME ", GetUptime},
|
||||||
{" ARCH ", GetArch},
|
{" ARCH ", GetArch},
|
||||||
{" SHELL ", GetShell},
|
{" SHELL ", GetShell},
|
||||||
{" PKGS ", GetPkg},
|
{" PKGS ", GetPkg},
|
||||||
{" RAM ", GetMem},
|
{" RAM ", GetMem},
|
||||||
{" ", Blank},
|
{" ", Blank},
|
||||||
{" COLORS ", PrintColors}
|
{" COLORS ", PrintColors}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
36
src/fetch.c
36
src/fetch.c
@ -5,11 +5,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
|
|
||||||
#if defined(__LINUX__) || defined(__ANDROID__)
|
|
||||||
#include <sys/sysinfo.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "fetch.h"
|
#include "fetch.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "logo.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 GetUptime(const char *title, const FETCH fetch) {
|
||||||
int hours = 0;
|
|
||||||
int mins = 0;
|
|
||||||
|
|
||||||
#ifdef CLOCK
|
#ifdef CLOCK
|
||||||
struct timespec uptime;
|
struct timespec uptime;
|
||||||
clock_gettime(CLOCK, &uptime);
|
clock_gettime(CLOCK, &uptime);
|
||||||
|
|
||||||
hours = uptime.tv_sec / 3600;
|
int days = uptime.tv_sec / 86400;
|
||||||
mins = (uptime.tv_sec / 60) - (uptime.tv_sec / 3600 * 60);
|
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);
|
||||||
|
|
||||||
printf("%s%s%s%dh %dm", fetch.color, title, fetch.font_color, hours, mins);
|
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -182,17 +180,17 @@ int GetPkg(const char *title, const FETCH fetch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int GetMem(const char *title, const FETCH fetch) {
|
int GetMem(const char *title, const FETCH fetch) {
|
||||||
#if defined(__LINUX__) || defined(__ANDROID__)
|
unsigned int free = 0, cache = 0, total = 0, unused;
|
||||||
struct sysinfo sinfo;
|
UNUSED(unused);
|
||||||
if (sysinfo(&sinfo) < 0)
|
|
||||||
|
FILE *fp = fopen("/proc/meminfo", "r");
|
||||||
|
if (fp == NULL)
|
||||||
return 1;
|
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%s%umb / %umb", fetch.color, title, fetch.font_color, (free + cache) / 1024, total / 1024);
|
||||||
printf("%s%s%s0mb / 0mb", fetch.color, title, fetch.font_color);
|
fclose(fp);
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,6 @@ int main(void) {
|
|||||||
for (; i < fetch.logo_size; i++)
|
for (; i < fetch.logo_size; i++)
|
||||||
printf("%s\n", fetch.logo[i]);
|
printf("%s\n", fetch.logo[i]);
|
||||||
|
|
||||||
printf("\033[0m\n");
|
printf("\033[0m");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user