mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 16:26:39 +01:00
--host-version
This commit is contained in:
+8
-17
@@ -5,28 +5,19 @@ void ffPrintHost(FFinstance* instance)
|
||||
if(ffPrintCachedValue(instance, "Host"))
|
||||
return;
|
||||
|
||||
char host[1024];
|
||||
|
||||
FILE* nameFile = fopen("/sys/devices/virtual/dmi/id/product_name", "r");
|
||||
if(nameFile == NULL)
|
||||
char host[256];
|
||||
ffGetFileContent("/sys/devices/virtual/dmi/id/product_name", host, sizeof(host) - 32); //We subtract 32 to have at least this padding for the version
|
||||
if(host[0] == '\0')
|
||||
{
|
||||
ffPrintError(instance, "Host", "fopen(\"/sys/devices/virtual/dmi/id/product_name\", \"r\") == NULL");
|
||||
ffPrintError(instance, "Host", "ffGetFileContent(\"/sys/devices/virtual/dmi/id/product_name\", host, sizeof(host)) failed");
|
||||
return;
|
||||
}
|
||||
if(fscanf(nameFile, "%[^\n]", host) != 1)
|
||||
{
|
||||
ffPrintError(instance, "Host", "fscanf(nameFile, \"%[^\\n]\", name) != 1");
|
||||
return;
|
||||
}
|
||||
fclose(nameFile);
|
||||
|
||||
FILE* versionFile = fopen("/sys/devices/virtual/dmi/id/product_version", "r");
|
||||
if(versionFile != NULL)
|
||||
if(instance->config.hostShowVersion)
|
||||
{
|
||||
ssize_t len = strlen(host);
|
||||
host[len] = ' ';
|
||||
if(fscanf(versionFile, "%[^\n]", host + len + 1) == 0); //fail silently, if reading of version fails, just show now version
|
||||
fclose(versionFile);
|
||||
size_t len = strlen(host);
|
||||
host[len++] = ' ';
|
||||
ffGetFileContent("/sys/devices/virtual/dmi/id/product_version", host + len, sizeof(host) - len);
|
||||
}
|
||||
|
||||
ffPrintAndSaveCachedValue(instance, "Host", host);
|
||||
|
||||
Reference in New Issue
Block a user