Skip to content

Commit

Permalink
options/glibc: Add the non *_r variants of hsearch
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennisbonke committed Oct 29, 2023
1 parent c370839 commit 50a8386
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions options/glibc/generic/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ struct _ENTRY {
size_t used;
};

static struct hsearch_data htab;

static size_t keyhash(char *k) {
unsigned char *p = (unsigned char *)k;
size_t h = 0;
Expand Down Expand Up @@ -123,3 +125,18 @@ void hdestroy_r(struct hsearch_data *htab) {
free(htab->table);
htab->table = 0;
}

int hcreate(size_t nel) {
return hcreate_r(nel, &htab);
}

void hdestroy(void) {
hdestroy_r(&htab);
}

ENTRY *hsearch(ENTRY item, ACTION action) {
ENTRY *e;

hsearch_r(item, action, &e, &htab);
return e;
}
4 changes: 4 additions & 0 deletions options/glibc/include/bits/glibc/glibc_search.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ struct hsearch_data {

#ifndef __MLIBC_ABI_ONLY

int hcreate(size_t nel);
void hdestroy(void);
ENTRY *hsearch(ENTRY item, ACTION action);

int hsearch_r(ENTRY item, ACTION action, ENTRY **ret, struct hsearch_data *htab);
int hcreate_r(size_t num_elements, struct hsearch_data *htab);
void hdestroy_r(struct hsearch_data *htab);
Expand Down

0 comments on commit 50a8386

Please sign in to comment.