From 01b699825d984fad297301d47784f69ff7f87044 Mon Sep 17 00:00:00 2001 From: bpc2003 Date: Thu, 13 Mar 2025 13:38:33 -0400 Subject: Added DEL command --- src/lib/keytab.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/lib/keytab.c') diff --git a/src/lib/keytab.c b/src/lib/keytab.c index 61f94af..5d0c7dd 100644 --- a/src/lib/keytab.c +++ b/src/lib/keytab.c @@ -37,14 +37,15 @@ struct keytab getkey(struct keytablist *list, int id, char *key) return list[id].tab[idx]; } -int setkey(struct keytablist **list, int *len, int id, char *pair) +int setkey(struct keytablist **list, int id, char *pair) { - if (id >= *len) { + if (id >= (*list)[0].len) { *list = realloc(*list, (id + 1) * sizeof(struct keytablist)); - for (int i = *len; i <= id; ++i) - (*list)[i] = empty; - *len = id + 1; - (*list)[0].len = *len; + for (int i = (*list)[0].len; i <= id; ++i) { + for (int j = 0; j < TABLEN; ++j) + (*list)[i].tab[j] = (struct keytab) {NULL, 0, {0}}; + } + (*list)[0].len = id + 1; } char *tok = strtok(pair, ":"); char *key = calloc(strlen(tok) + 1, sizeof(char)); @@ -89,6 +90,8 @@ int setkey(struct keytablist **list, int *len, int id, char *pair) void delkey(struct keytablist *list, int id, char *key) { int idx = hash(key); + if (list[id].tab[idx].key == NULL) + return; while (strcmp(list[id].tab[idx].key, key) && idx < TABLEN) idx++; if (idx >= TABLEN) { -- cgit v1.2.3