dll,launcher: invariant string comparisons

This commit is contained in:
Bill Zissimopoulos 2016-12-09 14:23:53 -08:00
parent 228f9e2708
commit 3a65ce332b
5 changed files with 49 additions and 18 deletions

View File

@ -107,7 +107,7 @@ static void fsp_fuse_opt_match_templ(
if ('%' == *p || '\0' == *p)
*pspec = p, *parg = q;
else
*parg = 0 == lstrcmpA(q, p) ?
*parg = 0 == invariant_strcmp(q, p) ?
fsp_fuse_opt_match_exact : fsp_fuse_opt_match_none;
}
else

View File

@ -252,7 +252,7 @@ static WCHAR FspNpGetDriveLetter(PDWORD PLogicalDrives, PWSTR VolumeName)
LocalNameBuf[0] = Drive;
if (QueryDosDeviceW(LocalNameBuf, VolumeNameBuf, sizeof VolumeNameBuf / sizeof(WCHAR)))
{
if (0 == lstrcmpW(VolumeNameBuf, VolumeName))
if (0 == invariant_wcscmp(VolumeNameBuf, VolumeName))
{
*PLogicalDrives &= ~(1 << (Drive - 'A'));
return Drive;
@ -432,7 +432,7 @@ DWORD APIENTRY NPGetConnection(
{
if (L'\0' == *P)
{
if (0 == lstrcmpW(VolumeNameBuf, VolumeName))
if (0 == invariant_wcscmp(VolumeNameBuf, VolumeName))
{
/*
* Looks like this is a WinFsp device. Extract the VolumePrefix from the VolumeName.
@ -604,7 +604,7 @@ DWORD APIENTRY NPAddConnection(LPNETRESOURCEW lpNetResource, LPWSTR lpPassword,
RemoteNameSize = sizeof RemoteNameBuf / sizeof(WCHAR);
NpResult = NPGetConnection(LocalNameBuf, RemoteNameBuf, &RemoteNameSize);
if (WN_SUCCESS == NpResult)
NpResult = 0 == lstrcmpW(ExpectRemoteNameBuf, RemoteNameBuf) ? WN_SUCCESS : WN_NO_NETWORK;
NpResult = 0 == invariant_wcscmp(ExpectRemoteNameBuf, RemoteNameBuf) ? WN_SUCCESS : WN_NO_NETWORK;
else
NpResult = WN_NO_NETWORK;
}
@ -1036,9 +1036,7 @@ NTSTATUS FspNpRegister(VOID)
{
if (L',' == *P || '\0' == *P)
{
if (CSTR_EQUAL == CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE,
Part, (int)(P - Part),
L"" FSP_NP_NAME, (int)(sizeof L"" FSP_NP_NAME - sizeof(WCHAR)) / sizeof(WCHAR)))
if (0 == invariant_wcsncmp(Part, L"" FSP_NP_NAME, P - Part))
{
FoundProvider = TRUE;
break;
@ -1099,9 +1097,7 @@ NTSTATUS FspNpUnregister(VOID)
{
if (L',' == *P || '\0' == *P)
{
if (CSTR_EQUAL == CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE,
Part, (int)(P - Part),
L"" FSP_NP_NAME, (int)(sizeof L"" FSP_NP_NAME - sizeof(WCHAR)) / sizeof(WCHAR)))
if (0 == invariant_wcsncmp(Part, L"" FSP_NP_NAME, P - Part))
{
FoundProvider = TRUE;
break;

View File

@ -227,7 +227,7 @@ int wmain(int argc, wchar_t **argv)
if (0 == argc)
usage();
if (0 == lstrcmpW(L"start", argv[0]))
if (0 == invariant_wcscmp(L"start", argv[0]))
{
if (3 > argc || argc > 12)
usage();
@ -236,7 +236,7 @@ int wmain(int argc, wchar_t **argv)
FALSE);
}
else
if (0 == lstrcmpW(L"startWithSecret", argv[0]))
if (0 == invariant_wcscmp(L"startWithSecret", argv[0]))
{
if (4 > argc || argc > 13)
usage();
@ -245,7 +245,7 @@ int wmain(int argc, wchar_t **argv)
TRUE);
}
else
if (0 == lstrcmpW(L"stop", argv[0]))
if (0 == invariant_wcscmp(L"stop", argv[0]))
{
if (3 != argc)
usage();
@ -253,7 +253,7 @@ int wmain(int argc, wchar_t **argv)
return stop(PipeBuf, LAUNCHER_PIPE_BUFFER_SIZE, argv[1], argv[2]);
}
else
if (0 == lstrcmpW(L"info", argv[0]))
if (0 == invariant_wcscmp(L"info", argv[0]))
{
if (3 != argc)
usage();
@ -261,7 +261,7 @@ int wmain(int argc, wchar_t **argv)
return getinfo(PipeBuf, LAUNCHER_PIPE_BUFFER_SIZE, argv[1], argv[2]);
}
else
if (0 == lstrcmpW(L"list", argv[0]))
if (0 == invariant_wcscmp(L"list", argv[0]))
{
if (1 != argc)
usage();
@ -269,7 +269,7 @@ int wmain(int argc, wchar_t **argv)
return list(PipeBuf, LAUNCHER_PIPE_BUFFER_SIZE);
}
else
if (0 == lstrcmpW(L"quit", argv[0]))
if (0 == invariant_wcscmp(L"quit", argv[0]))
{
if (1 != argc)
usage();

View File

@ -157,8 +157,8 @@ static SVC_INSTANCE *SvcInstanceLookup(PWSTR ClassName, PWSTR InstanceName)
{
SvcInstance = CONTAINING_RECORD(ListEntry, SVC_INSTANCE, ListEntry);
if (0 == lstrcmpiW(ClassName, SvcInstance->ClassName) &&
0 == lstrcmpiW(InstanceName, SvcInstance->InstanceName))
if (0 == invariant_wcsicmp(ClassName, SvcInstance->ClassName) &&
0 == invariant_wcsicmp(InstanceName, SvcInstance->InstanceName))
return SvcInstance;
}

View File

@ -87,6 +87,41 @@ void *memmove(void *dst, const void *src, size_t siz)
return dst;
}
#define WINFSP_SHARED_MINIMAL_STRCMP(NAME, TYPE, CONV)\
static inline\
int NAME(const TYPE *s, const TYPE *t)\
{\
int v = 0;\
while (0 == (v = CONV(*s) - CONV(*t)) && *t)\
++s, ++t;\
return v;/*(0 < v) - (0 > v);*/\
}
#define WINFSP_SHARED_MINIMAL_STRNCMP(NAME, TYPE, CONV)\
static inline\
int NAME(const TYPE *s, const TYPE *t, size_t n)\
{\
int v = 0;\
const void *e = t + n;\
while (e > (const void *)t && 0 == (v = CONV(*s) - CONV(*t)) && *t)\
++s, ++t;\
return v;/*(0 < v) - (0 > v);*/\
}
static inline
unsigned invariant_toupper(unsigned c)
{
return ('a' <= c && c <= 'z') ? c & ~0x20 : c;
}
WINFSP_SHARED_MINIMAL_STRCMP(invariant_strcmp, char, (unsigned))
WINFSP_SHARED_MINIMAL_STRCMP(invariant_stricmp, char, invariant_toupper)
WINFSP_SHARED_MINIMAL_STRNCMP(invariant_strncmp, char, (unsigned))
WINFSP_SHARED_MINIMAL_STRNCMP(invariant_strnicmp, char, invariant_toupper)
WINFSP_SHARED_MINIMAL_STRCMP(invariant_wcscmp, wchar_t, (unsigned))
WINFSP_SHARED_MINIMAL_STRCMP(invariant_wcsicmp, wchar_t, invariant_toupper)
WINFSP_SHARED_MINIMAL_STRNCMP(invariant_wcsncmp, wchar_t, (unsigned))
WINFSP_SHARED_MINIMAL_STRNCMP(invariant_wcsnicmp, wchar_t, invariant_toupper)
#undef WINFSP_SHARED_MINIMAL_STRCMP
#undef WINFSP_SHARED_MINIMAL_STRNCMP
static inline void *MemAlloc(size_t Size)
{
return HeapAlloc(GetProcessHeap(), 0, Size);