8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / krb5 / dyn / dyn_insert.c
blob7fd4a0e10a1ee6e09eef8bc4b466f1543b5639b5
1 #pragma ident "%Z%%M% %I% %E% SMI"
3 /*
4 * This file is part of libdyn.a, the C Dynamic Object library. It
5 * contains the source code for the function DynInsert().
6 *
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.
15 #include <stdio.h>
16 #include <strings.h>
17 #include "dynP.h"
19 int DynInsert(obj, idx, els_in, num)
20 DynObjectP obj;
21 void *els_in;
22 int idx, num;
24 DynPtr els = (DynPtr) els_in;
25 int ret;
27 if (idx < 0 || idx > obj->num_el) {
28 if (obj->debug)
29 fprintf(stderr, "dyn: insert: index %d is not in [0,%d]\n",
30 idx, obj->num_el);
31 return DYN_BADINDEX;
34 if (num < 1) {
35 if (obj->debug)
36 fprintf(stderr, "dyn: insert: cannot insert %d elements\n",
37 num);
38 return DYN_BADVALUE;
41 if (obj->debug)
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)
47 return ret;
48 #ifdef HAVE_MEMMOVE
49 memmove(obj->array + obj->el_size*(idx + num),
50 obj->array + obj->el_size*idx,
51 (obj->num_el-idx)*obj->el_size);
52 #else
53 bcopy(obj->array + obj->el_size*idx,
54 obj->array + obj->el_size*(idx + num),
55 (obj->num_el-idx)*obj->el_size);
56 #endif
58 if (obj->debug)
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);
62 #ifdef HAVE_MEMMOVE
63 memmove(obj->array + obj->el_size*idx, els, obj->el_size*num);
64 #else
65 bcopy(els, obj->array + obj->el_size*idx, obj->el_size*num);
66 #endif
67 obj->num_el += num;
69 if (obj->debug)
70 fprintf(stderr, "dyn: insert: done.\n");
72 return DYN_OK;