From 8740b798f92e86f67b6aa947964f1271f5f67cd1 Mon Sep 17 00:00:00 2001 From: John Carr Date: Fri, 21 Aug 1992 02:51:53 +0000 Subject: [PATCH] Add function krb5_append_addresses, to concatenate two address lists git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2344 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/krb/copy_addrs.c | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/lib/krb5/krb/copy_addrs.c b/src/lib/krb5/krb/copy_addrs.c index cf5995f69..9520ad7ea 100644 --- a/src/lib/krb5/krb/copy_addrs.c +++ b/src/lib/krb5/krb/copy_addrs.c @@ -80,3 +80,56 @@ krb5_address ***outaddr; *outaddr = tempaddr; return 0; } + +/* + * Append an address array, to another address array, with fresh allocation. + * Note that this function may change the value of *outaddr even if it + * returns failure, but it will not change the contents of the list. + */ +krb5_error_code +krb5_append_addresses(inaddr, outaddr) +krb5_address * const * inaddr; +krb5_address ***outaddr; +{ + krb5_error_code retval; + krb5_address ** tempaddr; + krb5_address ** tempaddr2; + register int nelems; + register int norigelems; + + if (!inaddr) + return 0; + + tempaddr2 = *outaddr; + + for (nelems = 0; inaddr[nelems]; nelems++); + for (norigelems = 0; tempaddr2[norigelems]; norigelems++); + + tempaddr = realloc((char *)*outaddr, + (nelems + norigelems + 1) * sizeof(*tempaddr)); + if (!tempaddr) + return ENOMEM; + + /* The old storage has been freed. */ + *outaddr = tempaddr; + + + for (nelems = 0; inaddr[nelems]; nelems++) + if (retval = krb5_copy_addr(inaddr[nelems], + &tempaddr[norigelems + nelems])) + goto cleanup; + + tempaddr[norigelems + nelems] = 0; + return 0; + + cleanup: + while (--nelems >= 0) + krb5_free_address(tempaddr[norigelems + nelems]); + + /* Try to allocate a smaller amount of memory for *outaddr. */ + tempaddr = realloc((char *)tempaddr, (norigelems + 1) * sizeof(*tempaddr)); + if (tempaddr) + *outaddr = tempaddr; + return retval; +} + -- 2.26.2