mirror of
git://source.winehq.org/git/wine.git
synced 2024-09-06 21:51:00 +00:00
ntdll: Add bsearch_s.
Implementation copied from msvcrt. Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
d1cc31cebb
commit
5b36a00b4d
|
@ -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)
|
||||
|
@ -202,6 +205,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.@)
|
||||
*/
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue