summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2013-12-04 12:10:37 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2013-12-04 12:10:37 +0100
commitb187a34ad9bc81921d24010e398c97b9501650e4 (patch)
treedd8477d8b57cfede9ef5aa3b7264d11f1fa5fe17 /src/util.c
parent49676b96484523543f53a19f9da1a9cb6a825b46 (diff)
downloadcmumble-b187a34ad9bc81921d24010e398c97b9501650e4.tar.gz
cmumble-b187a34ad9bc81921d24010e398c97b9501650e4.tar.bz2
cmumble-b187a34ad9bc81921d24010e398c97b9501650e4.zip
Get OS name from /etc/os-release
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index b2549af..1f6fd41 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1,4 +1,7 @@
#include "util.h"
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
#include <glib.h>
gpointer
@@ -16,3 +19,46 @@ cmumble_find_by_id(GList *list, gsize member_offset, guint id)
return el;
}
+
+gchar *
+cmumble_get_os_name(void)
+{
+ FILE *f;
+ char *line = NULL;
+ char *os = NULL, *value, *end;
+ size_t key_len = strlen("PRETTY_NAME=");
+ size_t n;
+
+ f = fopen("/etc/os-release", "r");
+ if (f == NULL)
+ return NULL;
+
+ while (getline(&line, &n, f) != -1) {
+ if (strncmp("PRETTY_NAME=", line, key_len) == 0 && (n - key_len) > 1) {
+ value = &line[key_len];
+ if (strlen(value) == 0)
+ continue;
+
+ end = &value[strlen(value) - 1];
+ if (*end == '\n')
+ *end-- = '\0';
+
+ if (strlen(value) < 2)
+ continue;
+
+ if (value[0] == '"')
+ value++;
+
+ if (*end == '"')
+ *end = '\0';
+
+ os = strdup(value);
+ goto out;
+ }
+ }
+
+out:
+ free(line);
+ fclose(f);
+ return os;
+}