From 7a17c3a4ea869a04041ff2568fd02ec676ab8dff Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 28 Oct 2022 00:48:14 +0100 Subject: large refactor continues --- common.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 common.c (limited to 'common.c') diff --git a/common.c b/common.c new file mode 100644 index 0000000..f217001 --- /dev/null +++ b/common.c @@ -0,0 +1,31 @@ +#include +#include + + +#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; +} + -- cgit v1.2.3