|
|
1.1 ! root 1: /* $Header: slappend.c,v 1.2 85/03/18 13:18:28 nicklin Exp $ */ ! 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 <stdio.h> ! 13: #include "macro.h" ! 14: #include "null.h" ! 15: #include "slist.h" ! 16: ! 17: extern char *PGN; /* program name */ ! 18: ! 19: char * ! 20: slappend(key, slist) ! 21: char *key; /* key string */ ! 22: SLIST *slist; /* pointer to list head block */ ! 23: { ! 24: char *malloc(); /* memory allocator */ ! 25: char *strcpy(); /* string copy */ ! 26: int strlen(); /* string length */ ! 27: SLBLK *slbptr; /* pointer to list block */ ! 28: unsigned int klen; /* key length */ ! 29: ! 30: if (slist == NULL) ! 31: return(NULL); ! 32: klen = strlen(key); ! 33: slist->maxkey = MAX(slist->maxkey, klen); ! 34: if ((slbptr = (SLBLK *) malloc(sizeof(SLBLK))) == NULL || ! 35: (slbptr->key = malloc(klen+1)) == NULL) ! 36: { ! 37: if (*PGN != '\0') ! 38: fprintf(stderr, "%s: ", PGN); ! 39: fprintf(stderr, "out of memory\n"); ! 40: return(NULL); ! 41: } ! 42: strcpy(slbptr->key, key); ! 43: slbptr->next = NULL; ! 44: if (slist->tail == NULL) ! 45: slist->head = slist->tail = slbptr; ! 46: else ! 47: slist->tail = slist->tail->next = slbptr; ! 48: slist->nk++; ! 49: return(slbptr->key); ! 50: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.