1: /*
   2: ** Routines for fiddlin' linked lists
   3: ** Erik E. Fair <fair@ucbarpa.berkeley.edu>
   4: */
   5: 
   6: #include <sys/types.h>
   7: #include "llist.h"
   8: 
   9: extern free();
  10: extern caddr_t  malloc();
  11: 
  12: /*
  13: ** a little wasteful for some cases, but it works, and I don't mind
  14: ** the extra padding - think of it as insurance.
  15: */
  16: #define ALIGN(x)    ((x) + (sizeof(long) - (x) % sizeof(long)))
  17: 
  18: /*
  19: ** recursively free a linked list
  20: */
  21: void
  22: l_free(lp)
  23: register ll_t *lp;
  24: {
  25:     if (lp->l_next == (ll_t *)NULL)
  26:         return;
  27:     l_free(lp->l_next);
  28:     (void) free(lp->l_item);
  29: }
  30: 
  31: /*
  32: ** allocate a new element in a linked list, along with enough space
  33: ** at the end of the item for the next list element header.
  34: */
  35: ll_t *
  36: l_alloc(lp, s, len)
  37: register ll_t   *lp;
  38: caddr_t s;
  39: register int len;
  40: {
  41:     if (s == (caddr_t)NULL || lp == (ll_t *)NULL || len <= 0)
  42:         return((ll_t *)NULL);
  43: 
  44:     lp->l_len = len;
  45:     len = ALIGN(len);
  46: 
  47:     if ((lp->l_item = malloc((unsigned)len + sizeof(ll_t))) == (caddr_t)NULL)
  48:         return((ll_t *)NULL);
  49: 
  50:     bcopy(s, lp->l_item, lp->l_len);
  51:     lp->l_next = (ll_t *)(&lp->l_item[len]);
  52: 
  53:     /*
  54: 	** set up next list entry
  55: 	*/
  56:     lp = lp->l_next;
  57:     lp->l_next = (ll_t *)NULL;
  58:     lp->l_item = (caddr_t)NULL;
  59:     lp->l_len = 0;
  60:     return(lp);
  61: }

Defined functions

l_alloc defined in line 35; used 2 times
l_free defined in line 21; used 3 times

Defined macros

ALIGN defined in line 16; used 1 times
  • in line 45
Last modified: 1987-11-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2415
Valid CSS Valid XHTML 1.0 Strict