1: /* $Header$ */
   2: 
   3: /*
   4:  * Author: Peter J. Nicklin
   5:  */
   6: 
   7: /*
   8:  * slprepend() saves a null-terminated key string somewhere and inserts a
   9:  * pointer to the key at the head 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: slprepend(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:     if (slist->head == NULL)
  39:         {
  40:         slbptr->next = NULL;
  41:         slist->head = slist->tail = slbptr;
  42:         }
  43:     else    {
  44:         slbptr->next = slist->head;
  45:         slist->head = slbptr;
  46:         }
  47:     slist->nk++;
  48:     return(slbptr->key);
  49: }

Defined functions

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