Files
fastfetch/src/host.c
T

38 lines
945 B
C
Raw Normal View History

2021-02-18 22:25:36 +01:00
#include "fastfetch.h"
2021-02-22 16:52:51 +01:00
#include <string.h>
2021-02-18 22:25:36 +01:00
void ffPrintHost(FFstate* state)
{
2021-02-22 16:52:51 +01:00
if(ffPrintCachedValue(state, "Host"))
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-20 19:08:23 +01:00
ffPrintError(state, "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-20 19:08:23 +01:00
ffPrintError(state, "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] = ' ';
fscanf(versionFile, "%[^\n]", host + len + 1);
2021-02-19 16:23:41 +01:00
fclose(versionFile);
}
2021-02-22 16:52:51 +01:00
ffSaveCachedValue(state, "Host", host);
ffPrintLogoAndKey(state, "Host");
puts(host);
2021-02-18 22:25:36 +01:00
}