[dovecot-cvs] dovecot/src/lib strfuncs.c, 1.43, 1.44 strfuncs.h,
1.22, 1.23
cras at dovecot.org
cras at dovecot.org
Thu Jan 6 20:09:10 EET 2005
Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv30497
Modified Files:
strfuncs.c strfuncs.h
Log Message:
Added strarray_join().
Index: strfuncs.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/strfuncs.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- strfuncs.c 26 Dec 2004 09:09:25 -0000 1.43
+++ strfuncs.c 6 Jan 2005 18:09:08 -0000 1.44
@@ -558,6 +558,34 @@
return count;
}
+const char *strarray_join(const char *const *arr, const char *separator)
+{
+ size_t alloc_len, sep_len, len, pos, needed_space;
+ char *str;
+
+ alloc_len = 64;
+ str = t_buffer_get(alloc_len);
+
+ for (pos = 0; *arr != NULL; arr++) {
+ len = strlen(*arr);
+ needed_space = pos + len + sep_len + 1;
+ if (needed_space < alloc_len) {
+ alloc_len = nearest_power(needed_space);
+ str = t_buffer_reget(str, alloc_len);
+ }
+
+ if (pos != 0) {
+ memcpy(str + pos, separator, sep_len);
+ pos += sep_len;
+ }
+
+ memcpy(str + pos, *arr, len);
+ pos += len;
+ }
+ str[pos] = '\0';
+ return str;
+}
+
const char *dec2str(uintmax_t number)
{
char *buffer;
Index: strfuncs.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/strfuncs.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- strfuncs.h 26 Dec 2004 09:09:25 -0000 1.22
+++ strfuncs.h 6 Jan 2005 18:09:08 -0000 1.23
@@ -67,6 +67,8 @@
/* Return length of NULL-terminated list string array */
unsigned int strarray_length(const char *const *arr);
+/* Return all strings from array joined into one string. */
+const char *strarray_join(const char *const *arr, const char *separator);
/* INTERNAL */
const char *_vstrconcat(const char *str1, va_list args, size_t *ret_len);
More information about the dovecot-cvs
mailing list