aboutsummaryrefslogtreecommitdiffstats
path: root/libgamma_group_name.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-03-05 00:43:38 +0100
committerMattias Andrée <maandree@kth.se>2021-03-05 00:43:38 +0100
commit0ce0d8d6e0c420ccafa79e0203b928c3559a4311 (patch)
tree88e8228a93691c28811a49898abf86a96dd9d613 /libgamma_group_name.c
parentChange license + change style + misc (diff)
downloadlibgamma-0ce0d8d6e0c420ccafa79e0203b928c3559a4311.tar.gz
libgamma-0ce0d8d6e0c420ccafa79e0203b928c3559a4311.tar.bz2
libgamma-0ce0d8d6e0c420ccafa79e0203b928c3559a4311.tar.xz
Split source files, merge public header files, eliminite use gpp, rewrite makefile
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--libgamma_group_name.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/libgamma_group_name.c b/libgamma_group_name.c
new file mode 100644
index 0000000..ce59300
--- /dev/null
+++ b/libgamma_group_name.c
@@ -0,0 +1,44 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+static _Thread_local char group_name[64]; /* Group names can only be up to 16 bytes logn, 63 is a very safe number */
+
+
+/**
+ * Get the group that the user needs to be a member of
+ * if `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned
+ *
+ * @return The group that the user needs to be a member of if
+ * `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, `NULL`
+ * if the name of the group `libgamma_group_gid` cannot
+ * be determined
+ */
+const char *
+libgamma_group_name_get(void)
+{
+ return *group_name ? group_name : NULL;
+}
+
+
+/**
+ * Set the group that the user needs to be a member of
+ * if `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned
+ *
+ * @param value The group that the user needs to be a member of if
+ * `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, may be `NULL`
+ */
+void
+libgamma_group_name_set(const char *value)
+{
+ size_t n;
+ if (!value) {
+ *group_name = 0;
+ } else {
+ n = strlen(value);
+ if (n >= sizeof(group_name))
+ *group_name = 0;
+ else
+ memcpy(group_name, value, n + 1);
+ }
+}