aboutsummaryrefslogtreecommitdiffstats
path: root/libgamma_group_name.c
blob: ce593000643e2ffb2b63a95924141257cd32cf20 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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);
	}
}