diff options
author | bpc2003 <wpesfriendnva@gmail.com> | 2025-03-13 13:38:33 -0400 |
---|---|---|
committer | bpc2003 <wpesfriendnva@gmail.com> | 2025-03-13 13:38:33 -0400 |
commit | 01b699825d984fad297301d47784f69ff7f87044 (patch) | |
tree | c97c1b4a496c248e58b562dc64ba4b1112ab1d0c /src/lib/keytab.c | |
parent | 82c5e54243a971c94da6e57976ffe7d43147af2a (diff) |
Added DEL command
Diffstat (limited to 'src/lib/keytab.c')
-rw-r--r-- | src/lib/keytab.c | 15 |
1 files changed, 9 insertions, 6 deletions
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) { |