Skip to content

Commit

Permalink
options/glibc: Implement hcreate_r/hdestroy_r/hsearch_r
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwinci committed May 27, 2024
1 parent 21680de commit e88c79c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
14 changes: 14 additions & 0 deletions options/glibc/generic/search.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <bits/glibc/glibc_search.h>
#include <mlibc/search.hpp>

int hcreate_r(size_t num_entries, hsearch_data *htab) {
return mlibc::hcreate_r(num_entries, htab);
}

void hdestroy_r(hsearch_data *htab) {
mlibc::hdestroy_r(htab);
}

int hsearch_r(ENTRY item, ACTION action, ENTRY **ret, hsearch_data *htab) {
return mlibc::hsearch_r(item, action, ret, htab);
}
22 changes: 22 additions & 0 deletions options/glibc/include/bits/glibc/glibc_search.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef _GLIBC_SEARCH_H
#define _GLIBC_SEARCH_H

#ifdef __cplusplus
extern "C" {
#endif

#include <bits/search.h>

#ifndef __MLIBC_ABI_ONLY

int hcreate_r(size_t num_entries, struct hsearch_data *htab);
void hdestroy_r(struct hsearch_data *htab);
int hsearch_r(ENTRY item, ACTION action, ENTRY **ret, 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_assert.h',
'include/bits/glibc/glibc_malloc.h',
'include/bits/glibc/glibc_icmp6.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 @@ -17,6 +17,10 @@ typedef enum {
leaf
} VISIT;

#if __MLIBC_GLIBC_OPTION && defined(_GNU_SOURCE)
#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 e88c79c

Please sign in to comment.