Commit 5b36a00b authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Add bsearch_s.

Implementation copied from msvcrt. Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent d1cc31ce
......@@ -179,18 +179,21 @@ void __cdecl qsort( void *base, size_t nmemb, size_t size,
/*********************************************************************
* bsearch (NTDLL.@)
* bsearch_s (NTDLL.@)
*/
void * __cdecl bsearch( const void *key, const void *base, size_t nmemb,
size_t size, int (__cdecl *compar)(const void *, const void *) )
void * __cdecl bsearch_s( const void *key, const void *base, size_t nmemb, size_t size,
int (__cdecl *compare)(void *, const void *, const void *), void *ctx )
{
ssize_t min = 0;
ssize_t max = nmemb - 1;
if (!size) return NULL;
if (!compare) return NULL;
while (min <= max)
{
ssize_t cursor = min + (max - min) / 2;
int ret = compar(key,(const char *)base+(cursor*size));
int ret = compare(ctx, key,(const char *)base+(cursor*size));
if (!ret)
return (char*)base+(cursor*size);
if (ret < 0)
......@@ -203,6 +206,17 @@ void * __cdecl bsearch( const void *key, const void *base, size_t nmemb,
/*********************************************************************
* bsearch (NTDLL.@)
*/
void * __cdecl bsearch( const void *key, const void *base, size_t nmemb,
size_t size, int (__cdecl *compar)(const void *, const void *) )
{
return bsearch_s( key, base, nmemb, size, compare_wrapper, compar );
}
/*********************************************************************
* _lfind (NTDLL.@)
*/
void * __cdecl _lfind( const void *key, const void *base, unsigned int *nmemb,
......
......@@ -1566,6 +1566,7 @@
@ cdecl atoi(str)
@ cdecl atol(str)
@ cdecl bsearch(ptr ptr long long ptr)
@ cdecl bsearch_s(ptr ptr long long ptr ptr)
@ cdecl ceil(double)
@ cdecl cos(double)
@ cdecl fabs(double)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment