test-priorityq.c \
test-seq-range-array.c \
test-strescape.c \
+ test-strfuncs.c \
test-str-find.c \
test-str-sanitize.c \
test-time-util.c \
return FALSE;
}
+const char **p_strarray_dup(pool_t pool, const char *const *arr)
+{
+ unsigned int i;
+ const char **ret;
+ char *p;
+ size_t len, size = sizeof(const char *);
+
+ for (i = 0; arr[i] != NULL; i++)
+ size += sizeof(const char *) + strlen(arr[i]) + 1;
+
+ ret = p_malloc(pool, size);
+ p = PTR_OFFSET(ret, sizeof(const char *) * (i + 1));
+ for (i = 0; arr[i] != NULL; i++) {
+ len = strlen(arr[i]) + 1;
+ memcpy(p, arr[i], len);
+ ret[i] = p;
+ p += len;
+ }
+ i_assert(PTR_OFFSET(ret, size) == (void *)p);
+ return ret;
+}
+
const char *dec2str(uintmax_t number)
{
char *buffer;
bool str_array_find(const char *const *arr, const char *value);
/* Like str_array_find(), but use strcasecmp(). */
bool str_array_icase_find(const char *const *arr, const char *value);
+/* Duplicate array of strings. The memory can be freed by freeing the
+ return value. */
+const char **p_strarray_dup(pool_t pool, const char *const *arr);
/* INTERNAL */
char *t_noalloc_strdup_vprintf(const char *format, va_list args,
test_priorityq,
test_seq_range_array,
test_strescape,
+ test_strfuncs,
test_str_find,
test_str_sanitize,
test_time_util,
void test_priorityq(void);
void test_seq_range_array(void);
void test_strescape(void);
+void test_strfuncs(void);
void test_str_find(void);
void test_str_sanitize(void);
void test_time_util(void);
--- /dev/null
+/* Copyright (c) 2009 Dovecot authors, see the included COPYING file */
+
+#include "test-lib.h"
+
+static void test_p_strarray_dup(void)
+{
+ const char *input[][3] = {
+ { NULL },
+ { "a", NULL },
+ { "foobar", NULL },
+ { "a", "foo", NULL }
+ };
+ const char **ret;
+ unsigned int i, j;
+
+ test_begin("p_strarray_dup");
+
+ for (i = 0; i < N_ELEMENTS(input); i++) {
+ ret = p_strarray_dup(default_pool, input[i]);
+ for (j = 0; input[i][j] != NULL; j++) {
+ test_assert(strcmp(input[i][j], ret[j]) == 0);
+ test_assert(input[i][j] != ret[j]);
+ }
+ test_assert(ret[j] == NULL);
+ i_free(ret);
+ }
+ test_end();
+}
+
+void test_strfuncs(void)
+{
+ test_p_strarray_dup();
+}