commit a178b7952303a2bd8b4b89c6ceb1862fb829513d
parent 133bb33a6f7609a10addaa1cc0cc5f37fdf19c01
Author: sam-barr <samfbarr@outlook.com>
Date: Wed, 22 Apr 2020 15:34:35 -0500
Merge pull request #15 from dwzg/product_version
Add product version to host
Diffstat:
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/paleofetch.c b/paleofetch.c
@@ -42,6 +42,11 @@ struct sysinfo my_sysinfo;
int title_length;
int status;
+void remove_newline(char *s) {
+ while (*(++s) != '\n');
+ *s = '\0';
+}
+
void halt_and_catch_fire(const char *message) {
if(status != 0) {
printf("%s\n", message);
@@ -143,10 +148,23 @@ char *get_host() {
fread(host, 1, BUF_SIZE, product_name);
fclose(product_name);
- // trim trailing newline
- char *s = host;
- while(*(++s) != '\n') ;
- *s = '\0';
+ FILE *product_version = fopen("/sys/devices/virtual/dmi/id/product_version", "r");
+
+ if(product_version == NULL) {
+ status = -1;
+ halt_and_catch_fire("unable to open product version file");
+ }
+
+ char version[BUF_SIZE];
+
+ fread(version, 1, BUF_SIZE, product_version);
+ fclose(product_version);
+
+ remove_newline(host);
+ remove_newline(version);
+
+ strcat(host, " ");
+ strcat(host, version);
return host;
}