|
|
|
|
|
|
|
|
|
|
|
|
|
|
| #include <corecrt_internal.h>
|
| #include <search.h>
|
| #include <cfguard.h>
|
|
|
| #ifdef _M_CEE
|
| #define __fileDECL __clrcall
|
| #else
|
| #define __fileDECL __cdecl
|
| #endif
|
|
|
|
|
|
|
| #ifdef __USE_CONTEXT
|
| #define __COMPARE(context, p1, p2) (*compare)(context, p1, p2)
|
| #else
|
| #define __COMPARE(context, p1, p2) (*compare)(p1, p2)
|
| #endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| #ifndef _M_CEE
|
| extern "C"
|
| DECLSPEC_GUARDNOCF
|
| #endif
|
| #ifdef __USE_CONTEXT
|
| void* __fileDECL _lfind_s(
|
| void const* const key,
|
| void const* const base,
|
| unsigned int* const num,
|
| size_t const width,
|
| int (__fileDECL* const compare)(void*, void const*, void const*),
|
| void* const context
|
| )
|
| #else
|
| void* __fileDECL _lfind(
|
| void const* const key,
|
| void const* const base,
|
| unsigned int* const num,
|
| unsigned int const width,
|
| int (__fileDECL* const compare)(void const*, void const*)
|
| )
|
| #endif
|
| {
|
| _VALIDATE_RETURN(key != nullptr, EINVAL, nullptr);
|
| _VALIDATE_RETURN(num != nullptr, EINVAL, nullptr);
|
| _VALIDATE_RETURN(base != nullptr || *num == 0, EINVAL, nullptr);
|
| _VALIDATE_RETURN(width > 0, EINVAL, nullptr);
|
| _VALIDATE_RETURN(compare != nullptr, EINVAL, nullptr);
|
|
|
| _GUARD_CHECK_ICALL(compare);
|
|
|
| char const* const first = static_cast<char const*>(base);
|
| char const* const last = first + *num * width;
|
|
|
| for (char const* p = first; p != last; p += width)
|
| {
|
| if (__COMPARE(context, key, const_cast<char*>(p)) == 0)
|
| {
|
| return const_cast<char*>(p);
|
| }
|
| }
|
|
|
| return nullptr;
|
| }
|
|
|
| #undef __COMPARE
|
|
|