|
20 | 20 | #include <sys/sysinfo.h>
|
21 | 21 | #endif
|
22 | 22 | #if defined(__NetBSD__)
|
23 |
| -#include <sys/sysctl.h> |
24 | 23 | #include <sys/swap.h>
|
| 24 | +#include <sys/sysctl.h> |
25 | 25 | #include <time.h>
|
26 | 26 | #endif
|
27 | 27 | #if defined(__FreeBSD__) || defined(__MacOS__)
|
@@ -468,14 +468,15 @@ int get_swap_stats(long long *total, long long *used, long long *free_mem) {
|
468 | 468 | (*total) = 0;
|
469 | 469 | (*used) = 0;
|
470 | 470 | (*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); |
473 | 474 | int devices = swapctl(SWAP_STATS, ent, nswap);
|
474 | 475 | 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; |
479 | 480 | }
|
480 | 481 | (*total) *= 512;
|
481 | 482 | (*used) *= 512;
|
@@ -511,10 +512,18 @@ int get_swap_stats(long long *total, long long *used, long long *free) {
|
511 | 512 | void tinyascii(void) {
|
512 | 513 | if (ascii_enable == 1) {
|
513 | 514 | #ifdef __NetBSD__
|
514 |
| - char *distro_name = strdup("NetBSD"); |
| 515 | + char *distro_name = strdup("NetBSD"); |
515 | 516 | #else
|
516 | 517 | char *distro_name =
|
517 | 518 | 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 | + } |
518 | 527 | #endif
|
519 | 528 | if (distro_name == NULL)
|
520 | 529 | distro_name = "L"; // generic Linux ascii
|
@@ -617,11 +626,17 @@ void tinydist(void) {
|
617 | 626 | printf("%s", tinyascii_p2);
|
618 | 627 | pretext(pretext_distro);
|
619 | 628 | #ifdef __NetBSD__
|
620 |
| - char* distro_name = strdup("NetBSD"); |
| 629 | + char *distro_name = strdup("NetBSD"); |
621 | 630 | #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 | + } |
625 | 640 | #endif
|
626 | 641 | #ifdef __NetBSD__
|
627 | 642 | char *distro_ver = NULL;
|
@@ -810,7 +825,8 @@ void tinycpu(void) {
|
810 | 825 | #if defined(__FreeBSD__) || defined(__MacOS__) || defined(__NetBSD__)
|
811 | 826 | #ifdef __NetBSD__
|
812 | 827 | 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"); |
814 | 830 | #else
|
815 | 831 | char *cpu = freebsd_sysctl_str("hw.model");
|
816 | 832 | #endif
|
|
0 commit comments