1: /* $Header$ */
   2: 
   3: /*
   4:  * Author: Peter J. Nicklin
   5:  */
   6: 
   7: /*
   8:  * slappend() saves a null-terminated key string somewhere and inserts a
   9:  * pointer to the key at the tail of list slist. Returns a pointer to
  10:  * the somewhere, or a null pointer if out of memory.
  11:  */
  12: #include "macro.h"
  13: #include "null.h"
  14: #include "slist.h"
  15: 
  16: char *
  17: slappend(key, slist)
  18:     char *key;          /* key string */
  19:     SLIST *slist;           /* pointer to list head block */
  20: {
  21:     char *malloc();         /* memory allocator */
  22:     char *strcpy();         /* string copy */
  23:     int strlen();           /* string length */
  24:     SLBLK *slbptr;          /* pointer to list block */
  25:     unsigned int klen;      /* key length */
  26: 
  27:     if (slist == NULL)
  28:         return(NULL);
  29:     klen = strlen(key);
  30:     slist->maxkey = MAX(slist->maxkey, klen);
  31:     if ((slbptr = (SLBLK *) malloc(sizeof(SLBLK))) == NULL ||
  32:         (slbptr->key = malloc(klen+1)) == NULL)
  33:         {
  34:         warn("out of memory");
  35:         return(NULL);
  36:         }
  37:     strcpy(slbptr->key, key);
  38:     slbptr->next = NULL;
  39:     if (slist->tail == NULL)
  40:         slist->head = slist->tail = slbptr;
  41:     else
  42:         slist->tail = slist->tail->next = slbptr;
  43:     slist->nk++;
  44:     return(slbptr->key);
  45: }

Defined functions

slappend defined in line 16; never used
Last modified: 1985-07-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 688
Valid CSS Valid XHTML 1.0 Strict