Files
fastfetch/src/modules/host.c
T

33 lines
972 B
C
Raw Normal View History

2021-02-18 22:25:36 +01:00
#include "fastfetch.h"
2021-02-27 18:30:05 +01:00
void ffPrintHost(FFinstance* instance)
2021-02-18 22:25:36 +01:00
{
2021-02-27 18:30:05 +01:00
if(ffPrintCachedValue(instance, "Host"))
2021-02-22 16:52:51 +01:00
return;
char host[1024];
2021-02-19 16:23:41 +01:00
FILE* nameFile = fopen("/sys/devices/virtual/dmi/id/product_name", "r");
if(nameFile == NULL)
{
2021-02-27 18:30:05 +01:00
ffPrintError(instance, "Host", "fopen(\"/sys/devices/virtual/dmi/id/product_name\", \"r\") == NULL");
2021-02-19 16:23:41 +01:00
return;
}
2021-02-22 16:52:51 +01:00
if(fscanf(nameFile, "%[^\n]", host) != 1)
2021-02-19 16:23:41 +01:00
{
2021-02-27 18:30:05 +01:00
ffPrintError(instance, "Host", "fscanf(nameFile, \"%[^\\n]\", name) != 1");
2021-02-19 16:23:41 +01:00
return;
}
fclose(nameFile);
2021-02-18 22:25:36 +01:00
2021-02-19 16:23:41 +01:00
FILE* versionFile = fopen("/sys/devices/virtual/dmi/id/product_version", "r");
if(versionFile != NULL)
{
2021-02-22 16:52:51 +01:00
ssize_t len = strlen(host);
host[len] = ' ';
2021-02-22 17:14:46 +01:00
if(fscanf(versionFile, "%[^\n]", host + len + 1) == 0); //fail silently, if reading of version fails, just show now version
2021-02-19 16:23:41 +01:00
fclose(versionFile);
}
2021-02-22 16:52:51 +01:00
2021-02-27 18:30:05 +01:00
ffPrintAndSaveCachedValue(instance, "Host", host);
2021-02-18 22:25:36 +01:00
}