paleofetch

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit fdab2c5ff30947c640c70023e5b8b9dac6758b3d
parent 69605e26778c53bba682e6544e4eae26b250b844
Author: sam-barr <samfbarr@outlook.com>
Date:   Fri,  1 May 2020 16:06:31 -0500

added fallback for get_host

Diffstat:
Mpaleofetch.c | 52++++++++++++++++++++++++++--------------------------
1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/paleofetch.c b/paleofetch.c @@ -145,36 +145,36 @@ static char *get_kernel() { } static char *get_host() { - FILE *product_name = fopen("/sys/devices/virtual/dmi/id/product_name", "r"); - - if(product_name == NULL) { - status = -1; - halt_and_catch_fire("unable to open product name file"); + char *host = malloc(BUF_SIZE), buffer[BUF_SIZE/2]; + FILE *product_name, *product_version, *model; + + if((product_name = fopen("/sys/devices/virtual/dmi/id/product_name", "r")) != NULL) { + if((product_version = fopen("/sys/devices/virtual/dmi/id/product_version", "r")) != NULL) { + fread(host, 1, BUF_SIZE/2, product_name); + remove_newline(host); + strcat(host, " "); + fread(buffer, 1, BUF_SIZE/2, product_version); + remove_newline(buffer); + strcat(host, buffer); + fclose(product_version); + } else { + fclose(product_name); + goto model_fallback; + } + fclose(product_name); + return host; } - char *host = malloc(BUF_SIZE); - fread(host, 1, BUF_SIZE, product_name); - fclose(product_name); - - FILE *product_version = fopen("/sys/devices/virtual/dmi/id/product_version", "r"); - - if(product_version == NULL) { - status = -1; - halt_and_catch_fire("unable to open product version file"); +model_fallback: + if((model = fopen("/sys/firmware/devicetree/base/model", "r")) != NULL) { + fread(host, 1, BUF_SIZE, model); + remove_newline(host); + return host; } - char version[BUF_SIZE]; - - fread(version, 1, BUF_SIZE, product_version); - fclose(product_version); - - remove_newline(host); - remove_newline(version); - - strcat(host, " "); - strcat(host, version); - - return host; + status = -1; + halt_and_catch_fire("unable to get host"); + return NULL; } static char *get_uptime() {