diff options
author | Daniel Stenberg <daniel@haxx.se> | 2006-04-10 15:00:53 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2006-04-10 15:00:53 +0000 |
commit | 686d90745be4417127050ad4b36d0a5403def200 (patch) | |
tree | 786a63b7554065aa0514440adf35fd7b639ae94c /lib/hash.c | |
parent | 5dc02d53c3edebab7597cd4ada446273e3a6daa8 (diff) | |
download | curl-686d90745be4417127050ad4b36d0a5403def200.tar.gz |
First curl_multi_socket() commit. Should primarily be considered as an internal
code rearrange to fit the future better.
Diffstat (limited to 'lib/hash.c')
-rw-r--r-- | lib/hash.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/lib/hash.c b/lib/hash.c index 96ccaa7fb..26ea9c475 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -124,8 +124,11 @@ mk_hash_element(char *key, size_t key_len, const void *p) (struct curl_hash_element *) malloc(sizeof(struct curl_hash_element)); if(he) { - char *dup = strdup(key); + char *dup = malloc(key_len); if(dup) { + /* copy the key */ + memcpy(dup, key, key_len); + he->key = dup; he->key_len = key_len; he->ptr = (void *) p; @@ -179,6 +182,23 @@ Curl_hash_add(struct curl_hash *h, char *key, size_t key_len, void *p) return NULL; /* failure */ } +/* remove the identified hash entry, returns non-zero on failure */ +int Curl_hash_delete(struct curl_hash *h, char *key, size_t key_len) +{ + struct curl_llist_element *le; + struct curl_hash_element *he; + struct curl_llist *l = FETCH_LIST(h, key, key_len); + + for (le = l->head; le; le = le->next) { + he = le->ptr; + if (hash_key_compare(he->key, he->key_len, key, key_len)) { + Curl_llist_remove(l, le, (void *) h); + return 0; + } + } + return 1; +} + void * Curl_hash_pick(struct curl_hash *h, char *key, size_t key_len) { @@ -186,9 +206,7 @@ Curl_hash_pick(struct curl_hash *h, char *key, size_t key_len) struct curl_hash_element *he; struct curl_llist *l = FETCH_LIST(h, key, key_len); - for (le = l->head; - le; - le = le->next) { + for (le = l->head; le; le = le->next) { he = le->ptr; if (hash_key_compare(he->key, he->key_len, key, key_len)) { return he->ptr; |