1 #pragma ident "%Z%%M% %I% %E% SMI"
4 * This file is part of libdyn.a, the C Dynamic Object library. It
5 * contains the source code for the function DynInsert().
7 * There are no restrictions on this code; however, if you make any
8 * changes, I request that you document them so that I do not get
9 * credit or blame for your modifications.
11 * Written by Barr3y Jaspan, Student Information Processing Board (SIPB)
12 * and MIT-Project Athena, 1989.
19 int DynInsert(obj
, idx
, els_in
, num
)
24 DynPtr els
= (DynPtr
) els_in
;
27 if (idx
< 0 || idx
> obj
->num_el
) {
29 fprintf(stderr
, "dyn: insert: index %d is not in [0,%d]\n",
36 fprintf(stderr
, "dyn: insert: cannot insert %d elements\n",
42 fprintf(stderr
,"dyn: insert: Moving %d bytes from %d + %d to + %d\n",
43 (obj
->num_el
-idx
)*obj
->el_size
, obj
->array
,
44 obj
->el_size
*idx
, obj
->el_size
*(idx
+num
));
46 if ((ret
= _DynResize(obj
, obj
->num_el
+ num
)) != DYN_OK
)
49 memmove(obj
->array
+ obj
->el_size
*(idx
+ num
),
50 obj
->array
+ obj
->el_size
*idx
,
51 (obj
->num_el
-idx
)*obj
->el_size
);
53 bcopy(obj
->array
+ obj
->el_size
*idx
,
54 obj
->array
+ obj
->el_size
*(idx
+ num
),
55 (obj
->num_el
-idx
)*obj
->el_size
);
59 fprintf(stderr
, "dyn: insert: Copying %d bytes from %d to %d + %d\n",
60 obj
->el_size
*num
, els
, obj
->array
, obj
->el_size
*idx
);
63 memmove(obj
->array
+ obj
->el_size
*idx
, els
, obj
->el_size
*num
);
65 bcopy(els
, obj
->array
+ obj
->el_size
*idx
, obj
->el_size
*num
);
70 fprintf(stderr
, "dyn: insert: done.\n");