8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / krb5 / dyn / dyn_put.c
blob2da50b6ac822f889393e8f5db4c0c1334c3c21bd
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 functions DynGet() and DynAdd().
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>
18 #include "dynP.h"
20 DynPtr DynArray(obj)
21 DynObjectP obj;
23 if (obj->debug)
24 fprintf(stderr, "dyn: array: returning array pointer %d.\n",
25 obj->array);
27 return obj->array;
30 DynPtr DynGet(obj, num)
31 DynObjectP obj;
32 int num;
34 if (num < 0) {
35 if (obj->debug)
36 fprintf(stderr, "dyn: get: bad index %d\n", num);
37 return NULL;
40 if (num >= obj->num_el) {
41 if (obj->debug)
42 fprintf(stderr, "dyn: get: highest element is %d.\n",
43 obj->num_el);
44 return NULL;
47 if (obj->debug)
48 fprintf(stderr, "dyn: get: Returning address %d + %d.\n",
49 obj->array, obj->el_size*num);
51 return (DynPtr) obj->array + obj->el_size*num;
54 int DynAdd(obj, el)
55 DynObjectP obj;
56 void *el;
58 int ret;
60 ret = DynPut(obj, el, obj->num_el);
61 if (ret != DYN_OK)
62 return ret;
64 ++obj->num_el;
65 return ret;
69 * WARNING! There is a reason this function is not documented in the
70 * man page. If DynPut used to mutate already existing elements,
71 * everything will go fine. If it is used to add new elements
72 * directly, however, the state within the object (such as
73 * obj->num_el) will not be updated properly and many other functions
74 * in the library will lose. Have a nice day.
76 int DynPut(obj, el_in, idx)
77 DynObjectP obj;
78 void *el_in;
79 int idx;
81 DynPtr el = (DynPtr) el_in;
82 int ret;
84 if (obj->debug)
85 fprintf(stderr, "dyn: put: Writing %d bytes from %d to %d + %d\n",
86 obj->el_size, el, obj->array, idx*obj->el_size);
88 if ((ret = _DynResize(obj, idx)) != DYN_OK)
89 return ret;
91 #ifdef HAVE_MEMMOVE
92 memmove(obj->array + idx*obj->el_size, el, obj->el_size);
93 #else
94 bcopy(el, obj->array + idx*obj->el_size, obj->el_size);
95 #endif
97 if (obj->debug)
98 fprintf(stderr, "dyn: put: done.\n");
100 return DYN_OK;