diff options
Diffstat (limited to 'src/libmdsserver')
-rw-r--r-- | src/libmdsserver/util.c | 25 | ||||
-rw-r--r-- | src/libmdsserver/util.h | 9 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/libmdsserver/util.c b/src/libmdsserver/util.c index df11b1a..01f5cbe 100644 --- a/src/libmdsserver/util.c +++ b/src/libmdsserver/util.c @@ -30,6 +30,31 @@ #include <ctype.h> + +/** + * Convert a client ID string into a client ID integer + * + * @param str The client ID string + * @return The client ID integer + */ +uint64_t parse_client_id(const char* str) +{ + char client_words[22]; + char* client_high; + char* client_low; + uint64_t client; + + strcpy(client_high = client_words, str); + client_low = rawmemchr(client_words, ':'); + *client_low++ = '\0'; + client = (uint64_t)atoll(client_high); + client <<= 32; + client |= (uint64_t)atoll(client_low); + + return client; +} + + /** * Read an environment variable, but handle it as undefined if empty * diff --git a/src/libmdsserver/util.h b/src/libmdsserver/util.h index 1b533bb..00dfb58 100644 --- a/src/libmdsserver/util.h +++ b/src/libmdsserver/util.h @@ -20,9 +20,18 @@ #include <stddef.h> +#include <stdint.h> /** + * Convert a client ID string into a client ID integer + * + * @param str The client ID string + * @return The client ID integer + */ +uint64_t parse_client_id(const char* str); + +/** * Read an environment variable, but handle it as undefined if empty * * @param var The environment variable's name |