2 * lib/krb5/krb/copy_addrs.c
4 * Copyright 1990 by the Massachusetts Institute of Technology.
7 * Export of this software from the United States of America may
8 * require a specific license from the United States Government.
9 * It is the responsibility of any person or organization contemplating
10 * export to obtain such a license before exporting.
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of M.I.T. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. M.I.T. makes no representations about the suitability of
20 * this software for any purpose. It is provided "as is" without express
21 * or implied warranty.
24 * krb5_copy_addresses()
29 static krb5_error_code
30 krb5_copy_addr(context, inad, outad)
32 const krb5_address *inad;
37 if (!(tmpad = (krb5_address *)malloc(sizeof(*tmpad))))
40 if (!(tmpad->contents = (krb5_octet *)malloc(inad->length))) {
44 memcpy((char *)tmpad->contents, (char *)inad->contents, inad->length);
50 * Copy an address array, with fresh allocation.
52 krb5_error_code INTERFACE
53 krb5_copy_addresses(context, inaddr, outaddr)
55 krb5_address * const * inaddr;
56 krb5_address ***outaddr;
58 krb5_error_code retval;
59 krb5_address ** tempaddr;
60 register int nelems = 0;
67 while (inaddr[nelems]) nelems++;
69 /* one more for a null terminated list */
70 if (!(tempaddr = (krb5_address **) calloc(nelems+1, sizeof(*tempaddr))))
73 for (nelems = 0; inaddr[nelems]; nelems++) {
74 retval = krb5_copy_addr(context, inaddr[nelems], &tempaddr[nelems]);
76 krb5_free_addresses(context, tempaddr);
86 * Append an address array, to another address array, with fresh allocation.
87 * Note that this function may change the value of *outaddr even if it
88 * returns failure, but it will not change the contents of the list.
90 krb5_error_code INTERFACE
91 krb5_append_addresses(context, inaddr, outaddr)
93 krb5_address * const * inaddr;
94 krb5_address ***outaddr;
96 krb5_error_code retval;
97 krb5_address ** tempaddr;
98 krb5_address ** tempaddr2;
99 register int nelems = 0;
100 register int norigelems = 0;
105 tempaddr2 = *outaddr;
107 while (inaddr[nelems]) nelems++;
108 while (tempaddr2[norigelems]) norigelems++;
110 tempaddr = (krb5_address **) realloc((char *)*outaddr,
111 (nelems + norigelems + 1) * sizeof(*tempaddr));
115 /* The old storage has been freed. */
119 for (nelems = 0; inaddr[nelems]; nelems++) {
120 retval = krb5_copy_addr(context, inaddr[nelems],
121 &tempaddr[norigelems + nelems]);
126 tempaddr[norigelems + nelems] = 0;
130 while (--nelems >= 0)
131 krb5_free_address(context, tempaddr[norigelems + nelems]);
133 /* Try to allocate a smaller amount of memory for *outaddr. */
134 tempaddr = (krb5_address **) realloc((char *)tempaddr,
135 (norigelems + 1) * sizeof(*tempaddr));