- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 22:35:33 +00:00
|
|
|
/*
|
|
|
|
* Helper functions for ntdll
|
2002-03-09 23:29:33 +00:00
|
|
|
*
|
|
|
|
* Copyright 2000 Juergen Schmied
|
2010-05-09 11:09:47 +00:00
|
|
|
* Copyright 2010 Marcus Meissner
|
2002-03-09 23:29:33 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 22:35:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2001-11-06 20:57:11 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <math.h>
|
2008-12-09 18:33:06 +00:00
|
|
|
#ifdef HAVE_SYS_UTSNAME_H
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
#endif
|
2001-11-06 20:57:11 +00:00
|
|
|
|
2008-03-26 18:41:54 +00:00
|
|
|
#include "wine/library.h"
|
2002-03-09 23:29:33 +00:00
|
|
|
#include "wine/debug.h"
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 22:35:33 +00:00
|
|
|
#include "ntdll_misc.h"
|
|
|
|
|
2002-03-09 23:29:33 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 22:35:33 +00:00
|
|
|
|
2000-06-23 16:16:30 +00:00
|
|
|
#if defined(__GNUC__) && defined(__i386__)
|
|
|
|
#define DO_FPU(x,y) __asm__ __volatile__( x " %0;fwait" : "=m" (y) : )
|
|
|
|
#define POP_FPU(x) DO_FPU("fstpl",x)
|
|
|
|
#endif
|
|
|
|
|
2009-02-16 10:46:44 +00:00
|
|
|
LPCSTR debugstr_ObjectAttributes(const OBJECT_ATTRIBUTES *oa)
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 22:35:33 +00:00
|
|
|
{
|
2009-02-16 10:46:44 +00:00
|
|
|
if (!oa) return "<null>";
|
|
|
|
return wine_dbg_sprintf( "{name=%s, attr=0x%08x, hRoot=%p, sd=%p}\n",
|
|
|
|
debugstr_us(oa->ObjectName), oa->Attributes,
|
|
|
|
oa->RootDirectory, oa->SecurityDescriptor );
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 22:35:33 +00:00
|
|
|
}
|
|
|
|
|
2000-08-26 21:16:36 +00:00
|
|
|
LPCSTR debugstr_us( const UNICODE_STRING *us )
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 22:35:33 +00:00
|
|
|
{
|
2000-08-26 21:16:36 +00:00
|
|
|
if (!us) return "<null>";
|
2002-08-13 18:10:28 +00:00
|
|
|
return debugstr_wn(us->Buffer, us->Length / sizeof(WCHAR));
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 22:35:33 +00:00
|
|
|
}
|
|
|
|
|
2000-06-23 16:16:30 +00:00
|
|
|
/*********************************************************************
|
2001-06-20 23:03:14 +00:00
|
|
|
* _ftol (NTDLL.@)
|
2000-12-02 23:44:59 +00:00
|
|
|
*
|
|
|
|
* VERSION
|
|
|
|
* [GNUC && i386]
|
2000-06-23 16:16:30 +00:00
|
|
|
*/
|
2000-12-02 23:44:59 +00:00
|
|
|
#if defined(__GNUC__) && defined(__i386__)
|
2006-06-12 19:35:07 +00:00
|
|
|
LONGLONG CDECL NTDLL__ftol(void)
|
2000-06-23 16:16:30 +00:00
|
|
|
{
|
|
|
|
/* don't just do DO_FPU("fistp",retval), because the rounding
|
|
|
|
* mode must also be set to "round towards zero"... */
|
|
|
|
double fl;
|
|
|
|
POP_FPU(fl);
|
2003-08-19 01:03:08 +00:00
|
|
|
return (LONGLONG)fl;
|
2000-06-23 16:16:30 +00:00
|
|
|
}
|
2000-12-02 23:44:59 +00:00
|
|
|
#endif /* defined(__GNUC__) && defined(__i386__) */
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-06-20 23:03:14 +00:00
|
|
|
* _ftol (NTDLL.@)
|
2000-12-02 23:44:59 +00:00
|
|
|
*
|
|
|
|
* FIXME
|
|
|
|
* Should be register function
|
|
|
|
* VERSION
|
|
|
|
* [!GNUC && i386]
|
|
|
|
*/
|
2001-07-26 21:41:22 +00:00
|
|
|
#if !defined(__GNUC__) && defined(__i386__)
|
2006-06-12 19:35:07 +00:00
|
|
|
LONGLONG CDECL NTDLL__ftol(double fl)
|
2000-06-23 16:16:30 +00:00
|
|
|
{
|
|
|
|
FIXME("should be register function\n");
|
2003-08-19 01:03:08 +00:00
|
|
|
return (LONGLONG)fl;
|
2000-06-23 16:16:30 +00:00
|
|
|
}
|
2000-12-02 23:44:59 +00:00
|
|
|
#endif /* !defined(__GNUC__) && defined(__i386__) */
|
|
|
|
|
2000-06-23 16:16:30 +00:00
|
|
|
/*********************************************************************
|
2001-06-20 23:03:14 +00:00
|
|
|
* _CIpow (NTDLL.@)
|
2000-12-02 23:44:59 +00:00
|
|
|
* VERSION
|
|
|
|
* [GNUC && i386]
|
2000-06-23 16:16:30 +00:00
|
|
|
*/
|
2000-12-02 23:44:59 +00:00
|
|
|
#if defined(__GNUC__) && defined(__i386__)
|
2006-06-12 19:35:07 +00:00
|
|
|
double CDECL NTDLL__CIpow(void)
|
2000-06-23 16:16:30 +00:00
|
|
|
{
|
|
|
|
double x,y;
|
|
|
|
POP_FPU(y);
|
|
|
|
POP_FPU(x);
|
|
|
|
return pow(x,y);
|
|
|
|
}
|
2000-12-02 23:44:59 +00:00
|
|
|
#endif /* defined(__GNUC__) && defined(__i386__) */
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-06-20 23:03:14 +00:00
|
|
|
* _CIpow (NTDLL.@)
|
2000-12-02 23:44:59 +00:00
|
|
|
*
|
|
|
|
* FIXME
|
|
|
|
* Should be register function
|
|
|
|
*
|
|
|
|
* VERSION
|
|
|
|
* [!GNUC && i386]
|
|
|
|
*/
|
|
|
|
#if !defined(__GNUC__) && defined(__i386__)
|
2006-06-12 19:35:07 +00:00
|
|
|
double CDECL NTDLL__CIpow(double x,double y)
|
2000-06-23 16:16:30 +00:00
|
|
|
{
|
|
|
|
FIXME("should be register function\n");
|
|
|
|
return pow(x,y);
|
|
|
|
}
|
2000-12-02 23:44:59 +00:00
|
|
|
#endif /* !defined(__GNUC__) && defined(__i386__) */
|
|
|
|
|
2008-03-26 18:41:54 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* wine_get_version (NTDLL.@)
|
|
|
|
*/
|
|
|
|
const char * CDECL NTDLL_wine_get_version(void)
|
|
|
|
{
|
|
|
|
return wine_get_version();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* wine_get_build_id (NTDLL.@)
|
|
|
|
*/
|
|
|
|
const char * CDECL NTDLL_wine_get_build_id(void)
|
|
|
|
{
|
|
|
|
return wine_get_build_id();
|
|
|
|
}
|
|
|
|
|
2008-12-09 18:33:06 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* wine_get_host_version (NTDLL.@)
|
|
|
|
*/
|
|
|
|
void CDECL NTDLL_wine_get_host_version( const char **sysname, const char **release )
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SYS_UTSNAME_H
|
|
|
|
static struct utsname buf;
|
|
|
|
static int init_done;
|
|
|
|
|
|
|
|
if (!init_done)
|
|
|
|
{
|
|
|
|
uname( &buf );
|
|
|
|
init_done = 1;
|
|
|
|
}
|
|
|
|
if (sysname) *sysname = buf.sysname;
|
|
|
|
if (release) *release = buf.release;
|
|
|
|
#else
|
|
|
|
if (sysname) *sysname = "";
|
|
|
|
if (release) *release = "";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-04-18 18:31:41 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* abs (NTDLL.@)
|
|
|
|
*/
|
2006-06-12 19:35:07 +00:00
|
|
|
int CDECL NTDLL_abs( int i )
|
2006-04-18 18:31:41 +00:00
|
|
|
{
|
|
|
|
return abs( i );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* labs (NTDLL.@)
|
|
|
|
*/
|
2007-06-11 11:13:32 +00:00
|
|
|
LONG CDECL NTDLL_labs( LONG i )
|
2006-04-18 18:31:41 +00:00
|
|
|
{
|
|
|
|
return labs( i );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* atan (NTDLL.@)
|
|
|
|
*/
|
2006-06-12 19:35:07 +00:00
|
|
|
double CDECL NTDLL_atan( double d )
|
2006-04-18 18:31:41 +00:00
|
|
|
{
|
|
|
|
return atan( d );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* ceil (NTDLL.@)
|
|
|
|
*/
|
2006-06-12 19:35:07 +00:00
|
|
|
double CDECL NTDLL_ceil( double d )
|
2006-04-18 18:31:41 +00:00
|
|
|
{
|
|
|
|
return ceil( d );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* cos (NTDLL.@)
|
|
|
|
*/
|
2006-06-12 19:35:07 +00:00
|
|
|
double CDECL NTDLL_cos( double d )
|
2006-04-18 18:31:41 +00:00
|
|
|
{
|
|
|
|
return cos( d );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* fabs (NTDLL.@)
|
|
|
|
*/
|
2006-06-12 19:35:07 +00:00
|
|
|
double CDECL NTDLL_fabs( double d )
|
2006-04-18 18:31:41 +00:00
|
|
|
{
|
|
|
|
return fabs( d );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* floor (NTDLL.@)
|
|
|
|
*/
|
2006-06-12 19:35:07 +00:00
|
|
|
double CDECL NTDLL_floor( double d )
|
2006-04-18 18:31:41 +00:00
|
|
|
{
|
|
|
|
return floor( d );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* log (NTDLL.@)
|
|
|
|
*/
|
2006-06-12 19:35:07 +00:00
|
|
|
double CDECL NTDLL_log( double d )
|
2006-04-18 18:31:41 +00:00
|
|
|
{
|
|
|
|
return log( d );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* pow (NTDLL.@)
|
|
|
|
*/
|
2006-06-12 19:35:07 +00:00
|
|
|
double CDECL NTDLL_pow( double x, double y )
|
2006-04-18 18:31:41 +00:00
|
|
|
{
|
|
|
|
return pow( x, y );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* sin (NTDLL.@)
|
|
|
|
*/
|
2006-06-12 19:35:07 +00:00
|
|
|
double CDECL NTDLL_sin( double d )
|
2006-04-18 18:31:41 +00:00
|
|
|
{
|
|
|
|
return sin( d );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* sqrt (NTDLL.@)
|
|
|
|
*/
|
2006-06-12 19:35:07 +00:00
|
|
|
double CDECL NTDLL_sqrt( double d )
|
2006-04-18 18:31:41 +00:00
|
|
|
{
|
|
|
|
return sqrt( d );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* tan (NTDLL.@)
|
|
|
|
*/
|
2006-06-12 19:35:07 +00:00
|
|
|
double CDECL NTDLL_tan( double d )
|
2006-04-18 18:31:41 +00:00
|
|
|
{
|
|
|
|
return tan( d );
|
|
|
|
}
|
2010-05-09 11:09:47 +00:00
|
|
|
|
|
|
|
|
2010-05-12 05:53:39 +00:00
|
|
|
static void
|
2010-10-01 22:31:03 +00:00
|
|
|
NTDLL_mergesort( void *arr, void *barr, size_t elemsize, int(__cdecl *compar)(const void *, const void *),
|
|
|
|
size_t left, size_t right )
|
2010-05-09 11:09:47 +00:00
|
|
|
{
|
|
|
|
if(right>left) {
|
2010-10-01 22:31:03 +00:00
|
|
|
size_t i, j, k, m;
|
2010-10-04 22:03:34 +00:00
|
|
|
m=left+(right-left)/2;
|
2010-05-12 05:53:39 +00:00
|
|
|
NTDLL_mergesort( arr, barr, elemsize, compar, left, m);
|
|
|
|
NTDLL_mergesort( arr, barr, elemsize, compar, m+1, right);
|
2010-05-09 11:09:47 +00:00
|
|
|
|
|
|
|
#define X(a,i) ((char*)a+elemsize*(i))
|
2011-03-30 08:56:27 +00:00
|
|
|
for (k=left, i=left, j=m+1; i<=m && j<=right; k++) {
|
|
|
|
if (compar(X(arr, i), X(arr,j)) <= 0) {
|
|
|
|
memcpy(X(barr,k), X(arr, i), elemsize);
|
2010-05-09 11:09:47 +00:00
|
|
|
i++;
|
|
|
|
} else {
|
2011-03-30 08:56:27 +00:00
|
|
|
memcpy(X(barr,k), X(arr, j), elemsize);
|
|
|
|
j++;
|
2010-05-09 11:09:47 +00:00
|
|
|
}
|
|
|
|
}
|
2011-03-30 08:56:27 +00:00
|
|
|
if (i<=m)
|
|
|
|
memcpy(X(barr,k), X(arr,i), (m-i+1)*elemsize);
|
|
|
|
else
|
|
|
|
memcpy(X(barr,k), X(arr,j), (right-j+1)*elemsize);
|
|
|
|
|
|
|
|
memcpy(X(arr, left), X(barr, left), (right-left+1)*elemsize);
|
2010-05-09 11:09:47 +00:00
|
|
|
}
|
|
|
|
#undef X
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* qsort (NTDLL.@)
|
|
|
|
*/
|
|
|
|
void __cdecl NTDLL_qsort( void *base, size_t nmemb, size_t size,
|
|
|
|
int(__cdecl *compar)(const void *, const void *) )
|
|
|
|
{
|
2010-10-04 22:04:44 +00:00
|
|
|
void *secondarr;
|
|
|
|
if (nmemb < 2 || size == 0) return;
|
|
|
|
secondarr = RtlAllocateHeap (GetProcessHeap(), 0, nmemb*size);
|
2010-05-12 05:53:39 +00:00
|
|
|
NTDLL_mergesort( base, secondarr, size, compar, 0, nmemb-1 );
|
2010-05-09 11:09:47 +00:00
|
|
|
RtlFreeHeap (GetProcessHeap(),0, secondarr);
|
|
|
|
}
|
2010-05-12 15:26:33 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* bsearch (NTDLL.@)
|
|
|
|
*/
|
|
|
|
void * __cdecl
|
|
|
|
NTDLL_bsearch( const void *key, const void *base, size_t nmemb,
|
|
|
|
size_t size, int (__cdecl *compar)(const void *, const void *) )
|
|
|
|
{
|
2010-05-23 20:25:06 +00:00
|
|
|
ssize_t min = 0;
|
|
|
|
ssize_t max = nmemb - 1;
|
|
|
|
|
|
|
|
while (min <= max)
|
|
|
|
{
|
|
|
|
ssize_t cursor = (min + max) / 2;
|
|
|
|
int ret = compar(key,(const char *)base+(cursor*size));
|
2010-05-12 15:26:33 +00:00
|
|
|
if (!ret)
|
|
|
|
return (char*)base+(cursor*size);
|
|
|
|
if (ret < 0)
|
2010-05-23 20:25:06 +00:00
|
|
|
max = cursor - 1;
|
2010-05-12 15:26:33 +00:00
|
|
|
else
|
2010-05-23 20:25:06 +00:00
|
|
|
min = cursor + 1;
|
2010-05-12 15:26:33 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _lfind (NTDLL.@)
|
|
|
|
*/
|
|
|
|
void * __cdecl _lfind( const void *key, const void *base, unsigned int *nmemb,
|
|
|
|
size_t size, int(__cdecl *compar)(const void *, const void *) )
|
|
|
|
{
|
|
|
|
size_t i, n = *nmemb;
|
|
|
|
|
|
|
|
for (i=0;i<n;i++)
|
|
|
|
if (!compar(key,(char*)base+(size*i)))
|
|
|
|
return (char*)base+(size*i);
|
|
|
|
return NULL;
|
|
|
|
}
|