]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/libdyn/dyn_realloc.c
Initial revision
[1ts-debian.git] / zephyr / libdyn / dyn_realloc.c
1 /*
2  * This file is part of libdyn.a, the C Dynamic Object library.  It
3  * contains the source code for the internal function _DynRealloc().
4  *
5  * There are no restrictions on this code; however, if you make any
6  * changes, I request that you document them so that I do not get
7  * credit or blame for your modifications.
8  *
9  * Written by Barr3y Jaspan, Student Information Processing Board (SIPB)
10  * and MIT-Project Athena, 1989.
11  */
12
13 #include <stdio.h>
14
15 #include "dynP.h"
16
17 /*
18  * Ideally, this function should not be called from outside the
19  * library.  However, nothing will break if it is.
20  */
21 int _DynRealloc(obj, num_incs)
22    DynObject obj;
23    int num_incs;
24 {
25      DynPtr temp;
26      int new_size_in_bytes;
27      
28      new_size_in_bytes = obj->el_size*(obj->size + obj->inc*num_incs);
29
30      if (obj->debug)
31           fprintf(stderr,
32                   "dyn: alloc: Increasing object by %d bytes (%d incs).\n",
33                   obj->el_size*obj->inc*num_incs, num_incs);
34      
35      temp = (DynPtr) realloc(obj->array, new_size_in_bytes);
36      if (temp == NULL) {
37           if (obj->debug)
38                fprintf(stderr, "dyn: alloc: Out of memory.\n");
39           return DYN_NOMEM;
40      }
41      else {
42           obj->array = temp;
43           obj->size += obj->inc*num_incs;
44      }
45
46      if (obj->debug)
47           fprintf(stderr, "dyn: alloc: done.\n");
48           
49      return DYN_OK;
50 }