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 functions DynCreate() and
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.
23 #define DEFAULT_INC 100
26 static int default_increment
= DEFAULT_INC
;
28 DynObjectP
DynCreate(el_size
, inc
)
33 obj
= (DynObjectP
) malloc(sizeof(DynObjectRecP
));
38 obj
->array
= (DynPtr
) malloc(1);
40 obj
->array
= (DynPtr
) malloc(0);
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
;
50 DynObjectP
DynCopy(obj
)
55 obj1
= (DynObjectP
) malloc(sizeof(DynObjectRecP
));
59 obj1
->el_size
= obj
->el_size
;
60 obj1
->num_el
= obj
->num_el
;
61 obj1
->size
= obj
->size
;
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
) {
71 memcpy(obj
->array
, obj1
->array
,
72 (size_t) (obj1
->el_size
* obj1
->size
));
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
);
95 fprintf(stderr
, "dyn: release: freeing object structure.\n");