From: John Kohl Date: Fri, 4 May 1990 15:05:46 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: krb5-1.0-alpha2~677 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8e5169e49f66d1b6a7ab40dacb0c83fc5f0ded50;p=krb5.git *** empty log message *** git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@725 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/krb/copy_addrs.c b/src/lib/krb5/krb/copy_addrs.c new file mode 100644 index 000000000..5218f764b --- /dev/null +++ b/src/lib/krb5/krb/copy_addrs.c @@ -0,0 +1,69 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * . + * + * krb5_copy_addresses() + */ + +#if !defined(lint) && !defined(SABER) +static char rcsid_copy_addrs_c[] = +"$Id$"; +#endif /* !lint & !SABER */ + +#include +#include +#include + +#include + +static krb5_error_code +krb5_copy_addr(inad, outad) +const krb5_address *inad; +krb5_address **outad; +{ + krb5_address *tmpad; + + if (!(tmpad = (krb5_address *)malloc(sizeof(*tmpad)))) + return ENOMEM; + *tmpad = *inad; + if (!(tmpad->contents = (krb5_octet *)malloc(inad->length))) { + xfree(tmpad); + return ENOMEM; + } + bcopy((char *)inad->contents, (char *)tmpad->contents, inad->length); + *outad = tmpad; + return 0; +} + +/* + * Copy an address array, with fresh allocation. + */ +krb5_error_code +krb5_copy_addresses(inaddr, outaddr) +krb5_address * const * inaddr; +krb5_address ***outaddr; +{ + krb5_error_code retval; + krb5_address ** tempaddr; + register int nelems; + + for (nelems = 0; inaddr[nelems]; nelems++); + + /* one more for a null terminated list */ + if (!(tempaddr = (krb5_address **) calloc(nelems+1, sizeof(*tempaddr)))) + return ENOMEM; + + for (nelems = 0; inaddr[nelems]; nelems++) + if (retval = krb5_copy_addr(inaddr[nelems], &tempaddr[nelems])) { + krb5_free_address(tempaddr); + return ENOMEM; + } + + *outaddr = tempaddr; + return 0; +}