Skip to content

Commit

Permalink
options/glibc: Add hashmap extension stubs to search.h
Browse files Browse the repository at this point in the history
Add hsearch_r, hcreate_r and hdestroy_r stubs.
  • Loading branch information
Qwinci committed Oct 23, 2023
1 parent f8d33ed commit 0122f95
Show file tree
Hide file tree
Showing 4 changed files with 64 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
@@ -0,0 +1,17 @@
#include <bits/glibc/glibc_search.h>
#include <bits/ensure.h>

int hsearch_r(ENTRY, ACTION, ENTRY **, struct hsearch_data *) {
__ensure(!"Not implemented");
__builtin_unreachable();
}

int hcreate_r(size_t, struct hsearch_data *) {
__ensure(!"Not implemented");
__builtin_unreachable();
}

void hdestroy_r(struct hsearch_data *) {
__ensure(!"Not implemented");
__builtin_unreachable();
}
41 changes: 41 additions & 0 deletions options/glibc/include/bits/glibc/glibc_search.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef _GLIBC_SEARCH_H
#define _GLIBC_SEARCH_H

#ifdef __cplusplus
extern "C" {
#endif

#include <bits/size_t.h>

typedef enum {
FIND,
ENTER
} ACTION;

typedef struct entry {
char *key;
void *data;
} ENTRY;

struct _ENTRY;

struct hsearch_data {
struct _ENTRY *table;
unsigned int size;
unsigned int filled;
};

#ifndef __MLIBC_ABI_ONLY

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);

#endif

#ifdef __cplusplus
}
#endif

#endif /* _GLIBC_SEARCH_H */

2 changes: 2 additions & 0 deletions options/glibc/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ libc_sources += files(
'generic/glibc-assert.cpp',
'generic/malloc.cpp',
'generic/sys-io.cpp',
'generic/search.cpp',
)

if not no_headers
Expand Down Expand Up @@ -84,6 +85,7 @@ if not no_headers
'include/bits/glibc/glibc_signal.h',
'include/bits/glibc/glibc_assert.h',
'include/bits/glibc/glibc_malloc.h',
'include/bits/glibc/glibc_search.h',
subdir: 'bits/glibc'
)
endif
Expand Down
4 changes: 4 additions & 0 deletions options/posix/include/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ typedef enum {
leaf
} VISIT;

#if __MLIBC_GLIBC_OPTION
#include <bits/glibc/glibc_search.h>
#endif

#ifndef __MLIBC_ABI_ONLY

void *tsearch(const void *, void **, int(*compar)(const void *, const void *));
Expand Down

0 comments on commit 0122f95

Please sign in to comment.