#include <mit-copyright.h>
#include <ctype.h>
-#include <sms.h>
+#include <moira.h>
+#include <string.h>
+
+extern char *malloc();
#define NULL 0
#define hash_func(h, key) (key >= 0 ? (key % h->size) : (-key % h->size))
struct hash *h;
h = (struct hash *) malloc(sizeof(struct hash));
+ if (h == (struct hash *) NULL)
+ return((struct hash *) NULL);
h->size = size;
h->data = (struct bucket **) malloc(size * sizeof(char *));
- bzero(h->data, size * sizeof(char *));
+ if (h->data == (struct bucket **) NULL) {
+ free(h);
+ return((struct hash *) NULL);
+ }
+ memset(h->data, 0, size * sizeof(char *));
return(h);
}
/* Store an item in the hash table. Returns 0 if the key was not previously
- * there, or 1 if it was.
+ * there, 1 if it was, or -1 if we ran out of memory.
*/
int hash_store(h, key, value)
p = &(h->data[hash_func(h, key)]);
if (*p == NULL) {
b = *p = (struct bucket *) malloc(sizeof(struct bucket));
+ if (b == (struct bucket *) NULL)
+ return(-1);
b->next = NULL;
b->key = key;
b->data = value;
return(1);
}
b = *p = (struct bucket *) malloc(sizeof(struct bucket));
+ if (b == (struct bucket *) NULL)
+ return(-1);
b->next = NULL;
b->key = key;
b->data = value;