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 internal function _DynRealloc().
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.
21 * Resize the array so that element req exists.
23 int _DynResize(obj
, req
)
31 else if (obj
->inc
> 0)
32 return _DynRealloc(obj
, (req
- obj
->size
) / obj
->inc
+ 1);
42 return _DynRealloc(obj
, size
);
47 * Resize the array by num_incs units. If obj->inc is positive, this
48 * means make it obj->inc*num_incs elements larger. If obj->inc is
49 * negative, this means make the array num_incs elements long.
51 * Ideally, this function should not be called from outside the
52 * library. However, nothing will break if it is.
54 int _DynRealloc(obj
, num_incs
)
59 int new_size_in_bytes
;
62 new_size_in_bytes
= obj
->el_size
*(obj
->size
+ obj
->inc
*num_incs
);
64 new_size_in_bytes
= obj
->el_size
*num_incs
;
68 "dyn: alloc: Increasing object by %d bytes (%d incs).\n",
69 new_size_in_bytes
- obj
->el_size
*obj
->size
,
72 temp
= (DynPtr
) realloc(obj
->array
, new_size_in_bytes
);
75 fprintf(stderr
, "dyn: alloc: Out of memory.\n");
81 obj
->size
+= obj
->inc
*num_incs
;
87 fprintf(stderr
, "dyn: alloc: done.\n");