2 * This file is part of libdyn.a, the C Dynamic Object library. It
3 * contains the source code for the function DynInsert().
5 * There are no restrictions on this code; however, if you make any
6 * changes, I request that you document them so that I do not get
7 * credit or blame for your modifications.
9 * Written by Barr3y Jaspan, Student Information Processing Board (SIPB)
10 * and MIT-Project Athena, 1989.
15 int DynInsert(obj, idx, els, num)
22 if (idx < 0 || idx > obj->num_el) {
24 fprintf(stderr, "dyn: insert: index %d is not in [0,%d]\n",
31 fprintf(stderr, "dyn: insert: cannot insert %d elements\n",
37 fprintf(stderr,"dyn: insert: Moving %d bytes from %p + %d to + %d\n",
38 (obj->num_el-idx)*obj->el_size, obj->array,
39 obj->el_size*idx, obj->el_size*(idx+num));
41 if ((ret = _DynResize(obj, obj->num_el + num)) != DYN_OK)
44 (void) memmove(obj->array + (idx + num), obj->array + idx,
45 (obj->num_el-idx)*obj->el_size);
48 fprintf(stderr, "dyn: insert: Copying %d bytes from %p to %p + %d\n",
49 obj->el_size*num, els, obj->array, obj->el_size*idx);
51 (void) memmove(obj->array + obj->el_size*idx, els, obj->el_size*num);
56 fprintf(stderr, "dyn: insert: done.\n");