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.
16 DynInsert(DynObject obj,
24 if (idx < 0 || idx > obj->num_el) {
26 fprintf(stderr, "dyn: insert: index %d is not in [0,%d]\n",
33 fprintf(stderr, "dyn: insert: cannot insert %d elements\n",
39 fprintf(stderr,"dyn: insert: Moving %d bytes from %p + %d to + %d\n",
40 (obj->num_el-idx)*obj->el_size, obj->array,
41 obj->el_size*idx, obj->el_size*(idx+num));
43 if ((ret = _DynResize(obj, obj->num_el + num)) != DYN_OK)
46 (void) memmove(obj->array + (idx + num), obj->array + idx,
47 (obj->num_el-idx)*obj->el_size);
50 fprintf(stderr, "dyn: insert: Copying %d bytes from %p to %p + %d\n",
51 obj->el_size*num, els, obj->array, obj->el_size*idx);
53 (void) memmove(obj->array + obj->el_size*idx, els, obj->el_size*num);
58 fprintf(stderr, "dyn: insert: done.\n");