Skip to content

Commit 6f662ab

Browse files
committed
Bugfix: remove any " from /etc/os-release output
Some distrobutions like Debian put '"' around the NAME= in /etc/os-release. This patch will remove these from the fetch output. Signed-off-by: kernaltrap <[email protected]>
1 parent d7dafb1 commit 6f662ab

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

src/tinyfetch.c

+29-13
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#include <sys/sysinfo.h>
2121
#endif
2222
#if defined(__NetBSD__)
23-
#include <sys/sysctl.h>
2423
#include <sys/swap.h>
24+
#include <sys/sysctl.h>
2525
#include <time.h>
2626
#endif
2727
#if defined(__FreeBSD__) || defined(__MacOS__)
@@ -468,14 +468,15 @@ int get_swap_stats(long long *total, long long *used, long long *free_mem) {
468468
(*total) = 0;
469469
(*used) = 0;
470470
(*free_mem) = 0;
471-
if(nswap == 0) return 0;
472-
struct swapent* ent = malloc(sizeof(*ent) * nswap);
471+
if (nswap == 0)
472+
return 0;
473+
struct swapent *ent = malloc(sizeof(*ent) * nswap);
473474
int devices = swapctl(SWAP_STATS, ent, nswap);
474475
int i;
475-
for(i = 0; i < devices; i++){
476-
(*total) += ent[i].se_nblks;
477-
(*used) += ent[i].se_inuse;
478-
(*free_mem) += ent[i].se_nblks - ent[i].se_inuse;
476+
for (i = 0; i < devices; i++) {
477+
(*total) += ent[i].se_nblks;
478+
(*used) += ent[i].se_inuse;
479+
(*free_mem) += ent[i].se_nblks - ent[i].se_inuse;
479480
}
480481
(*total) *= 512;
481482
(*used) *= 512;
@@ -511,10 +512,18 @@ int get_swap_stats(long long *total, long long *used, long long *free) {
511512
void tinyascii(void) {
512513
if (ascii_enable == 1) {
513514
#ifdef __NetBSD__
514-
char *distro_name = strdup("NetBSD");
515+
char *distro_name = strdup("NetBSD");
515516
#else
516517
char *distro_name =
517518
file_parser_char("/etc/os-release", "PRETTY_NAME=\"%s\"");
519+
int len = strlen(distro_name);
520+
if (distro_name[0] == '"') {
521+
memmove(distro_name, distro_name + 1, len - 1);
522+
len--;
523+
}
524+
if (len > 0 && distro_name[len - 1] == '"') {
525+
distro_name[len - 1] = '\0';
526+
}
518527
#endif
519528
if (distro_name == NULL)
520529
distro_name = "L"; // generic Linux ascii
@@ -617,11 +626,17 @@ void tinydist(void) {
617626
printf("%s", tinyascii_p2);
618627
pretext(pretext_distro);
619628
#ifdef __NetBSD__
620-
char* distro_name = strdup("NetBSD");
629+
char *distro_name = strdup("NetBSD");
621630
#else
622-
char *distro_name = file_parser_char("/etc/os-release",
623-
"NAME=%s"); // parsing and isolating the
624-
// PRETTY_NAME and VERSON_ID
631+
char *distro_name = file_parser_char("/etc/os-release", "NAME=%s");
632+
int len = strlen(distro_name);
633+
if (distro_name[0] == '"') {
634+
memmove(distro_name, distro_name + 1, len - 1);
635+
len--;
636+
}
637+
if (len > 0 && distro_name[len - 1] == '"') {
638+
distro_name[len - 1] = '\0';
639+
}
625640
#endif
626641
#ifdef __NetBSD__
627642
char *distro_ver = NULL;
@@ -810,7 +825,8 @@ void tinycpu(void) {
810825
#if defined(__FreeBSD__) || defined(__MacOS__) || defined(__NetBSD__)
811826
#ifdef __NetBSD__
812827
char *cpu = freebsd_sysctl_str("machdep.cpu_brand");
813-
if(cpu == NULL) cpu = freebsd_sysctl_str("hw.model");
828+
if (cpu == NULL)
829+
cpu = freebsd_sysctl_str("hw.model");
814830
#else
815831
char *cpu = freebsd_sysctl_str("hw.model");
816832
#endif

src/tinyfetch.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/*
77
tinyfetch.h
88
*/
9-
#define VERSION "6.2"
9+
#define VERSION "6.3"
1010
#define decoration "[·]"
1111
#define CMDLINE_PATH "/proc/%d/cmdline"
1212
#define help_banner \

0 commit comments

Comments
 (0)