fix os parser
This commit is contained in:
parent
fe22f07134
commit
d4571a3f14
@ -14,9 +14,7 @@
|
|||||||
|
|
||||||
#define OS_SIZE 128
|
#define OS_SIZE 128
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char os_buf[OS_SIZE + 1];
|
char os_name[OS_SIZE + 1];
|
||||||
char *os_name;
|
|
||||||
|
|
||||||
struct utsname uts;
|
struct utsname uts;
|
||||||
|
|
||||||
char *pkg_cmd;
|
char *pkg_cmd;
|
||||||
|
27
src/fetch.c
27
src/fetch.c
@ -18,15 +18,9 @@ FETCH Init(void) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(fetch.os_buf, '\0', sizeof(fetch.os_buf));
|
memset(fetch.os_name, '\0', sizeof(fetch.os_name));
|
||||||
int ret = GetOs(fetch.os_buf, sizeof(fetch.os_buf));
|
if (GetOs(fetch.os_name, sizeof(fetch.os_name)))
|
||||||
fetch.os_name = fetch.os_buf;
|
snprintf(fetch.os_name, sizeof(fetch.os_name), "%s", fetch.uts.sysname);
|
||||||
|
|
||||||
if (ret)
|
|
||||||
snprintf(fetch.os_buf, sizeof(fetch.os_buf), "%s", fetch.uts.sysname);
|
|
||||||
|
|
||||||
else
|
|
||||||
fetch.os_name += strlen("PRETTY_NAME=\"");
|
|
||||||
|
|
||||||
fetch.font_color = FONT_COLOR;
|
fetch.font_color = FONT_COLOR;
|
||||||
GetArt(&fetch);
|
GetArt(&fetch);
|
||||||
@ -41,8 +35,15 @@ int GetOs(char *buf, size_t len) {
|
|||||||
while (fgets(buf, len, fp)) {
|
while (fgets(buf, len, fp)) {
|
||||||
if (!strncmp(buf, "PRETTY_NAME=\"", 5)) {
|
if (!strncmp(buf, "PRETTY_NAME=\"", 5)) {
|
||||||
buf[strlen(buf) - 2] = '\0';
|
buf[strlen(buf) - 2] = '\0';
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
|
char *tmp = strdup(buf);
|
||||||
|
if (tmp == NULL)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
snprintf(buf, len, "%s", tmp + strlen("PRETTY_NAME=\""));
|
||||||
|
free(tmp);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -190,12 +191,12 @@ int GetMem(const char *title, const FETCH fetch) {
|
|||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
unsigned int unused = 0, total = 0, available = 0;
|
unsigned int unused = 0, total = 0, available = 0, buffer = 0, cached = 0;
|
||||||
if (fscanf(fp, "MemTotal: %u kB\nMemFree: %u kB\nMemAvailable: %u kB\n", &total, &unused, &available) < 0)
|
if (fscanf(fp, "MemTotal: %u kB\nMemFree: %u kB\nMemAvailable: %u kB\nBuffers: %u kB\nCached: %u kB", &total, &unused, &available, &buffer, &cached) < 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
UNUSED(unused);
|
UNUSED(unused);
|
||||||
printf("%s%s%s%umb / %umb", fetch.color, title, fetch.font_color, (total - available) / 1024, total / 1024);
|
printf("%s%s%s%umb / %umb", fetch.color, title, fetch.font_color, (total - available - buffer - cached) / 1024, total / 1024);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user