From cda6cfcae4f65e7e8a1b55bede8cc68aa9905796 Mon Sep 17 00:00:00 2001 From: 4zv4l Date: Wed, 3 Nov 2021 15:34:41 +0100 Subject: [PATCH 1/2] adding a way to get the hostname for linux --- uwufetch.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index 9a87573..3046312 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -666,11 +666,17 @@ void get_info() #else FILE *cpuinfo = popen("sysctl -a | egrep -i 'hw.model'", "r"); #endif - FILE *host_model_info = fopen("/sys/devices/virtual/dmi/id/board_name", "r"); // first try open the file + FILE *host_model_info = fopen("/etc/hostname","r"); + if (!host_model_info) + host_model_info = fopen("/sys/devices/virtual/dmi/id/board_name", "r"); // first try open the file if (!host_model_info) // if failed - host_model_info = fopen("/sys/devices/virtual/dmi/id/product_name", "r"); // try open another file - if(host_model_info) // if one of the file could be open then close it - fclose(host_model_info); + host_model_info = fopen("/sys/devices/virtual/dmi/id/product_name", "r"); // try open another file + if(host_model_info) { + fgets(line, 256, host_model_info); + line[strlen(line)-1] = '\0'; + sprintf(host_model,"%s",line); + fclose(host_model_info); + } #ifdef __WINDOWS__ host_model_info = popen("wmic computersystem get model", "r"); while (fgets(line, sizeof(line), host_model_info)) From c02b53bc8aad06fcecd8b007fa1f6e02fd95378e Mon Sep 17 00:00:00 2001 From: 4zv4l Date: Wed, 3 Nov 2021 15:37:40 +0100 Subject: [PATCH 2/2] changed the comments to fit --- uwufetch.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index 3046312..7290411 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -666,12 +666,12 @@ void get_info() #else FILE *cpuinfo = popen("sysctl -a | egrep -i 'hw.model'", "r"); #endif - FILE *host_model_info = fopen("/etc/hostname","r"); + FILE *host_model_info = fopen("/etc/hostname","r"); // try open /etc/hostname first if (!host_model_info) - host_model_info = fopen("/sys/devices/virtual/dmi/id/board_name", "r"); // first try open the file + host_model_info = fopen("/sys/devices/virtual/dmi/id/board_name", "r"); // if couldn't then try another if (!host_model_info) // if failed - host_model_info = fopen("/sys/devices/virtual/dmi/id/product_name", "r"); // try open another file - if(host_model_info) { + host_model_info = fopen("/sys/devices/virtual/dmi/id/product_name", "r"); // etc. + if(host_model_info) { // if succeeded to open one of the file fgets(line, 256, host_model_info); line[strlen(line)-1] = '\0'; sprintf(host_model,"%s",line);