]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/libdyn/dyn_append.c
unpack of new upstream
[1ts-debian.git] / zephyr / libdyn / dyn_append.c
1 /*
2  * This file is part of libdyn.a, the C Dynamic Object library.  It
3  * contains the source code for the function DynAppend().
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 int DynAppend(obj, els, num)
18    DynObject obj;
19    DynPtr els;
20    int num;
21 {
22      if (obj->debug)
23           fprintf(stderr, "dyn: append: Writing %d bytes from %p to %p + %d\n",
24                   obj->el_size*num, els, obj->array, obj->num_el*obj->el_size);
25
26      if (obj->size < obj->num_el + num) {
27           int num_incs, ret;
28
29           num_incs = ((obj->num_el + num - obj->size) / obj->inc) + 1;
30           if ((ret = _DynRealloc(obj, num_incs)) != DYN_OK)
31                return ret;
32      }
33
34      (void) memmove(obj->array + obj->num_el*obj->el_size, els,
35                     obj->el_size*num);
36
37      obj->num_el += num;
38
39      if (obj->debug)
40           fprintf(stderr, "dyn: append: done.\n");
41
42      return DYN_OK;
43 }
44