/*
 * This file is part of libdyn.a, the C Dynamic Object library.  It
 * contains the source code for the function DynAppend().
 *
 * There are no restrictions on this code; however, if you make any
 * changes, I request that you document them so that I do not get
 * credit or blame for your modifications.
 *
 * Written by Barr3y Jaspan, Student Information Processing Board (SIPB)
 * and MIT-Project Athena, 1989.
 */

#include <stdio.h>
#include "DynObject.H"

int DynObject::Append(DynPtr els, int num)
{
     if (debug)
	  fprintf(stderr, "dyn: append: Writing %d bytes from %d to %d + %d\n",
		  el_size*num, els, array, num_el*el_size);

     if (size < num_el + num) {
	  int num_incs, ret;

	  num_incs = ((num_el + num - size) / inc) + 1;
	  if ((ret = Realloc(num_incs)) != DYN_OK)
	       return ret;
     }

     bcopy(els, array + num_el*el_size, el_size*num);

     num_el += num;

     if (debug)
	  fprintf(stderr, "dyn: append: done.\n");

     return DYN_OK;
}

