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 DynDelete().
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.
13 * Copyright (c) 2016 by Delphix. All rights reserved.
23 * Checkers! Get away from that "hard disk erase" button!
24 * (Stupid dog. He almost did it to me again ...)
26 int DynDelete(obj
, idx
)
32 fprintf(stderr
, "dyn: delete: bad index %d\n", idx
);
36 if (idx
>= obj
->num_el
) {
38 fprintf(stderr
, "dyn: delete: Highest index is %d.\n",
43 if (idx
== obj
->num_el
-1) {
46 fprintf(stderr
, "dyn: delete: last element, zeroing.\n");
47 memset(obj
->array
+ idx
*obj
->el_size
, 0, obj
->el_size
);
51 fprintf(stderr
, "dyn: delete: last element, punting.\n");
57 "dyn: delete: copying %d bytes from %d + %d to + %d.\n",
58 obj
->el_size
*(obj
->num_el
- idx
), obj
->array
,
59 (idx
+1)*obj
->el_size
, idx
*obj
->el_size
);
62 memmove(obj
->array
+ idx
*obj
->el_size
,
63 obj
->array
+ (idx
+1)*obj
->el_size
,
64 obj
->el_size
*(obj
->num_el
- idx
));
66 bcopy(obj
->array
+ (idx
+1)*obj
->el_size
,
67 obj
->array
+ idx
*obj
->el_size
,
68 obj
->el_size
*(obj
->num_el
- idx
));
73 "dyn: delete: zeroing %d bytes from %d + %d\n",
74 obj
->el_size
, obj
->array
,
75 obj
->el_size
*(obj
->num_el
- 1));
76 memset(obj
->array
+ obj
->el_size
*(obj
->num_el
- 1), 0,
84 fprintf(stderr
, "dyn: delete: done.\n");