diff --git a/lib/base/error.c b/lib/base/error.c index bc289d3d9..50d0bef88 100644 --- a/lib/base/error.c +++ b/lib/base/error.c @@ -144,13 +144,33 @@ heim_error_createv(int error_code, const char *fmt, va_list ap) heim_string_t heim_error_copy_string(heim_error_t error) { + heim_string_t acc = NULL; + heim_error_t e = error; + if (heim_get_tid(error) != HEIM_TID_ERROR) { if (heim_get_tid(error) == heim_number_get_type_id()) return __heim_string_constant(strerror(heim_number_get_int((heim_number_t)error))); heim_abort("invalid heim_error_t"); } - /* XXX concat all strings */ - return heim_retain(error->msg); + /* concat all strings */ + while (e) { + heim_string_t n; + const char *s; + + if (acc == NULL) { + acc = heim_retain(error->msg); + e = e->next; + continue; + } + if ((s = heim_string_get_utf8(e->msg))) { + n = heim_string_create_with_format("%s: %s", + heim_string_get_utf8(acc), s); + heim_release(acc); + acc = n; + } + e = e->next; + } + return acc; } int diff --git a/lib/base/string.c b/lib/base/string.c index 5e79e00b1..f25cb7137 100644 --- a/lib/base/string.c +++ b/lib/base/string.c @@ -189,6 +189,25 @@ heim_string_create_with_format(const char *fmt, ...) return s; } +/** + * Concatenate two strings + * + * @param left + * @param sep + * @param right + * + * @return string object + */ + +heim_string_t +heim_string_concat(heim_string_t left, const char *sep, heim_string_t right) +{ + const char *sleft = heim_string_get_utf8(left); + const char *sright = heim_string_get_utf8(right); + + return heim_string_create_with_format("%s%s%s", sleft, sep, sright); +} + /** * Return the type ID of string objects *