1: #include "llist.h"
   2: 
   3: extern void free();
   4: extern caddr_t  malloc();
   5: 
   6: #define align(x)    ((x) + ((x) % sizeof(long)))
   7: 
   8: /*
   9: ** recursively free a linked list
  10: */
  11: void
  12: l_free(lp)
  13: register struct llist *lp;
  14: {
  15:     if (lp->l_next == NULL)
  16:         return;
  17:     l_free(lp->l_next);
  18:     free(lp->l_item);
  19: }
  20: 
  21: /*
  22: ** allocate a new element in a linked list, along with enough space
  23: ** at the end of the item for the next list element header.
  24: */
  25: struct llist *
  26: l_alloc(lp, s, len)
  27: register struct llist   *lp;
  28: caddr_t *s;
  29: register unsigned len;
  30: {
  31:     if (s == NULL || lp == NULL)
  32:         return(NULL);
  33: 
  34:     lp->l_len = len;
  35:     len = align(len);
  36: 
  37:     if ((lp->l_item = malloc(len + sizeof(struct llist))) == NULL)
  38:         return(NULL);
  39: 
  40:     bcopy(s, lp->l_item, len);
  41:     lp->l_next = (struct llist *)(&lp->l_item[len]);
  42: 
  43:     /*
  44: 	** set up next list entry
  45: 	*/
  46:     lp = lp->l_next;
  47:     lp->l_next = NULL;
  48:     lp->l_item = NULL;
  49:     lp->l_len = 0;
  50:     return(lp);
  51: }

Defined functions

l_alloc defined in line 25; used 2 times
l_free defined in line 11; used 5 times

Defined macros

align defined in line 6; used 1 times
  • in line 35
Last modified: 1986-03-21
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 944
Valid CSS Valid XHTML 1.0 Strict