From c1e2da80dfa62793ea107cf12408c814e268a54b Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 4 May 2014 18:29:53 +0100 Subject: add string utility to join strings --- utils/utils.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'utils/utils.h') diff --git a/utils/utils.h b/utils/utils.h index db26ed176..33cb0e99a 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -28,6 +28,9 @@ #include #include #include +#include + +#include "utils/errors.h" struct dirent; @@ -145,6 +148,49 @@ char *human_friendly_bytesize(unsigned long bytesize); const char *rfc1123_date(time_t t); unsigned int wallclock(void); +/** + * Generate a string from one or more component elemnts separated with + * a single value. + * + * This is similar in intent to the perl join function creating a + * single delimited string from an array of several. + * + * @note If a string is allocated it must be freed by the caller. + * + * @param[in,out] str pointer to string pointer if this is NULL enough + * storage will be allocated for the complete path. + * @param[in,out] size The size of the space available if \a str not + * NULL on input and if not NULL set to the total + * output length on output. + * @param[in] sep The character to separete the elemnts with. + * @param[in] nemb The number of elements up to a maximum of 16. + * @param[in] ap The elements of the path as string pointers. + * @return NSERROR_OK and the complete path is written to str or error + * code on faliure. + */ +nserror vsnstrjoin(char **str, size_t *size, char sep, size_t nelm, va_list ap); + +/** + * Generate a string from one or more component elemnts separated with + * a single value. + * + * This is similar in intent to the perl join function creating a + * single delimited string from an array of several. + * + * @note If a string is allocated it must be freed by the caller. + * + * @param[in,out] str pointer to string pointer if this is NULL enough + * storage will be allocated for the complete path. + * @param[in,out] size The size of the space available if \a str not + * NULL on input and if not NULL set to the total + * output length on output. + * @param[in] sep The character to separete the elemnts with. + * @param[in] nemb The number of elements up to a maximum of 16. + * @param[in] ... The elements of the path as string pointers. + * @return NSERROR_OK and the complete path is written to str or error + * code on faliure. + */ +nserror snstrjoin(char **str, size_t *size, char sep, size_t nelm, ...); /** * Comparison function for sorting directories. -- cgit v1.2.3