From 0ce0d8d6e0c420ccafa79e0203b928c3559a4311 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 5 Mar 2021 00:43:38 +0100 Subject: Split source files, merge public header files, eliminite use gpp, rewrite makefile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libgamma_group_name.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 libgamma_group_name.c (limited to 'libgamma_group_name.c') 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); + } +} -- cgit v1.2.3-70-g09d2