adding a way to get the hostname for linux
This commit is contained in:
parent
e941d81815
commit
cda6cfcae4
1 changed files with 10 additions and 4 deletions
14
uwufetch.c
14
uwufetch.c
|
@ -666,11 +666,17 @@ void get_info()
|
||||||
#else
|
#else
|
||||||
FILE *cpuinfo = popen("sysctl -a | egrep -i 'hw.model'", "r");
|
FILE *cpuinfo = popen("sysctl -a | egrep -i 'hw.model'", "r");
|
||||||
#endif
|
#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
|
if (!host_model_info) // if failed
|
||||||
host_model_info = fopen("/sys/devices/virtual/dmi/id/product_name", "r"); // try open another file
|
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
|
if(host_model_info) {
|
||||||
fclose(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__
|
#ifdef __WINDOWS__
|
||||||
host_model_info = popen("wmic computersystem get model", "r");
|
host_model_info = popen("wmic computersystem get model", "r");
|
||||||
while (fgets(line, sizeof(line), host_model_info))
|
while (fgets(line, sizeof(line), host_model_info))
|
||||||
|
|
Loading…
Reference in a new issue