*** empty log message ***
authorJohn Kohl <jtkohl@mit.edu>
Fri, 4 May 1990 15:05:46 +0000 (15:05 +0000)
committerJohn Kohl <jtkohl@mit.edu>
Fri, 4 May 1990 15:05:46 +0000 (15:05 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@725 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/krb/copy_addrs.c [new file with mode: 0644]

diff --git a/src/lib/krb5/krb/copy_addrs.c b/src/lib/krb5/krb/copy_addrs.c
new file mode 100644 (file)
index 0000000..5218f76
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/mit-copyright.h>.
+ *
+ * krb5_copy_addresses()
+ */
+
+#if !defined(lint) && !defined(SABER)
+static char rcsid_copy_addrs_c[] =
+"$Id$";
+#endif /* !lint & !SABER */
+
+#include <krb5/copyright.h>
+#include <krb5/krb5.h>
+#include <errno.h>
+
+#include <krb5/ext-proto.h>
+
+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;
+}