8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / krb5 / dyn / dyn_delete.c
blob7cb8c750ff0b8a78e92a0b6f0dee638da6e1e8b7
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 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.
16 #include <stdio.h>
17 #include <strings.h>
18 #include <string.h>
20 #include "dynP.h"
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)
27 DynObjectP obj;
28 int idx;
30 if (idx < 0) {
31 if (obj->debug)
32 fprintf(stderr, "dyn: delete: bad index %d\n", idx);
33 return DYN_BADINDEX;
36 if (idx >= obj->num_el) {
37 if (obj->debug)
38 fprintf(stderr, "dyn: delete: Highest index is %d.\n",
39 obj->num_el);
40 return DYN_BADINDEX;
43 if (idx == obj->num_el-1) {
44 if (obj->paranoid) {
45 if (obj->debug)
46 fprintf(stderr, "dyn: delete: last element, zeroing.\n");
47 memset(obj->array + idx*obj->el_size, 0, obj->el_size);
49 else {
50 if (obj->debug)
51 fprintf(stderr, "dyn: delete: last element, punting.\n");
54 else {
55 if (obj->debug)
56 fprintf(stderr,
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);
61 #ifdef HAVE_MEMMOVE
62 memmove(obj->array + idx*obj->el_size,
63 obj->array + (idx+1)*obj->el_size,
64 obj->el_size*(obj->num_el - idx));
65 #else
66 bcopy(obj->array + (idx+1)*obj->el_size,
67 obj->array + idx*obj->el_size,
68 obj->el_size*(obj->num_el - idx));
69 #endif
70 if (obj->paranoid) {
71 if (obj->debug)
72 fprintf(stderr,
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,
77 obj->el_size);
81 --obj->num_el;
83 if (obj->debug)
84 fprintf(stderr, "dyn: delete: done.\n");
86 return DYN_OK;