8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / krb5 / dyn / dyn_create.c
bloba69ca4ce1319468d5be320ee8f5edda77893baab
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 DynCreate() and
6 * DynDestroy().
8 * There are no restrictions on this code; however, if you make any
9 * changes, I request that you document them so that I do not get
10 * credit or blame for your modifications.
12 * Written by Barr3y Jaspan, Student Information Processing Board (SIPB)
13 * and MIT-Project Athena, 1989.
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
20 #include "dynP.h"
22 #ifndef DEFAULT_INC
23 #define DEFAULT_INC 100
24 #endif
26 static int default_increment = DEFAULT_INC;
28 DynObjectP DynCreate(el_size, inc)
29 int el_size, inc;
31 DynObjectP obj;
33 obj = (DynObjectP) malloc(sizeof(DynObjectRecP));
34 if (obj == NULL)
35 return NULL;
37 #ifdef USE_DBMALLOC
38 obj->array = (DynPtr) malloc(1);
39 #else
40 obj->array = (DynPtr) malloc(0);
41 #endif
42 obj->el_size = el_size;
43 obj->num_el = obj->size = 0;
44 obj->debug = obj->paranoid = 0;
45 obj->inc = (!! inc) ? inc : default_increment;
47 return obj;
50 DynObjectP DynCopy(obj)
51 DynObjectP obj;
53 DynObjectP obj1;
55 obj1 = (DynObjectP) malloc(sizeof(DynObjectRecP));
56 if (obj1 == NULL)
57 return NULL;
59 obj1->el_size = obj->el_size;
60 obj1->num_el = obj->num_el;
61 obj1->size = obj->size;
62 obj1->inc = obj->inc;
63 obj1->debug = obj->debug;
64 obj1->paranoid = obj->paranoid;
65 obj1->initzero = obj->initzero;
66 obj1->array = (char *) malloc(obj1->el_size * obj1->size);
67 if (obj1->array == NULL) {
68 free(obj1);
69 return NULL;
71 memcpy(obj->array, obj1->array,
72 (size_t) (obj1->el_size * obj1->size));
74 return obj1;
77 int DynDestroy(obj)
78 DynObjectP obj;
80 if (obj->paranoid) {
81 if (obj->debug)
82 fprintf(stderr, "dyn: destroy: zeroing %d bytes from %d.\n",
83 obj->el_size * obj->size, obj->array);
84 memset(obj->array, 0, obj->el_size * obj->size);
86 free(obj->array);
87 free(obj);
88 return DYN_OK;
91 int DynRelease(obj)
92 DynObjectP obj;
94 if (obj->debug)
95 fprintf(stderr, "dyn: release: freeing object structure.\n");
96 free(obj);
97 return DYN_OK;