diff options
Diffstat (limited to '')
-rw-r--r-- | src/client.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/client.c b/src/client.c index fb08c49..9df327e 100644 --- a/src/client.c +++ b/src/client.c @@ -20,6 +20,7 @@ * DEALINGS IN THE SOFTWARE. */ #include "client.h" +#include <string.h> @@ -47,3 +48,39 @@ send_command(enum command cmd, size_t n, const char *restrict msg) return 0 /* TODO */ } + + +/** + * Return the number of bytes required to store a string array. + * + * @param array The string array. + * @return The number of bytes required to store the array. + */ +size_t +measure_array(char *array[]) +{ + size_t rc = 1; + for (; *array; array++) + rc += strlen(*array) + 1; + return rc * sizeof(char); +} + + +/** + * Store a string array. + * + * @param storage The buffer where the array is to be stored. + * @param array The array to store. + * @return Where in the buffer the array ends. + */ +char * +store_array(char *restrict storage, char *array[]) +{ + for (; *array; array++) { + storage = stpcpy(storage, *array); + *storage++ = 0; + } + *storage++ = 0; + return storage; +} + |