aboutsummaryrefslogtreecommitdiff
path: root/common.c
blob: f2170019cdef68540aec61b9f4e5ec063737e8d0 (plain)
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
#include <stdio.h>
#include <string.h>


#define SOCKDIR "/run/apionet"

int
channel_socket_path(char chname[], char out[], size_t lim)
{
	if (strlen(chname) > 16) return -1;
	if (snprintf(out, lim, SOCKDIR "/apionet.%s.sock", chname) >= lim)
		return -1;
	return 0;
}

char *channels[] = {
	"a","b","robots","jonathan","secret-channel",NULL,
};

int
main()
{
	char b[200];
	for (int i = 0; channels[i]; i++) {
		memset(b,0,200);
		channel_socket_path(channels[i], b, 200);
		printf("%s\n",b);
	}
	return 0;
}