mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-11-07 04:36:52 -10:00
libc: Implement bsearch_s(), document bsearch_b(), and add unit tests
- Implement bsearch_s() as per §K.3.6.3.2 in C23, first specified in C11. It behaves identically to bsearch(), except the callback is called with a third argument, context, which is passed through from the caller, and it also performs runtime constraint checking on its arguments. - Document bsearch_b(), bsearch_s(), and add history section - Add rudimentary unit tests for bsearch(), bsearch_b(), and bsearch_s() Reviewed by: dteske, fuz Approved by: dteske (mentor), fuz (mentor) MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D58876
This commit is contained in:
11 files changed
+503
-6
No files matched your search
@@ -411,6 +411,9 @@ _Noreturn void abort_handler_s(const char * __restrict, void * __restrict,
|
||||
/* K3.6.1.3 */
|
||||
void ignore_handler_s(const char * __restrict, void * __restrict, errno_t);
|
||||
/* K.3.6.3.2 */
|
||||
void *bsearch_s(const void *, const void *, rsize_t, rsize_t,
|
||||
int (*)(const void *, const void *, void *), void *);
|
||||
/* K.3.6.3.3 */
|
||||
errno_t qsort_s(void *, rsize_t, rsize_t,
|
||||
int (*)(const void *, const void *, void *), void *);
|
||||
#endif /* __EXT1_VISIBLE */
|
||||
@@ -428,6 +431,13 @@ __NULLABILITY_PRAGMA_POP
|
||||
(const void *)(bsearch_b)((key), (base), (nmemb), (size), (compar)), \
|
||||
(bsearch_b)((key), (base), (nmemb), (size), (compar)))
|
||||
#endif
|
||||
#if __EXT1_VISIBLE
|
||||
#define bsearch_s(key, base, nmemb, size, compar, context) \
|
||||
__qualsel((base), \
|
||||
(const void *)(bsearch_s)((key), (base), (nmemb), (size), \
|
||||
(compar), (context)), \
|
||||
(bsearch_s)((key), (base), (nmemb), (size), (compar), (context)))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* !_STDLIB_H_ */
|
||||
Reference in new issue
Block a user