ATF_TC_BODY(mbsnrtowcs, tc) { size_t i; const struct test *t; mbstate_t state; wchar_t buf[64]; const char *src; size_t len; for (i = 0; i < __arraycount(tests); ++i) { t = &tests[i]; ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C"); ATF_REQUIRE(setlocale(LC_CTYPE, t->locale) != NULL); memset(&state, 0, sizeof(state)); src = t->data; len = mbsnrtowcs(buf, &src, t->limit, __arraycount(buf), &state); ATF_REQUIRE_EQ(src, t->data + t->limit); ATF_REQUIRE_EQ(len, t->output1_len); ATF_REQUIRE(wmemcmp(t->output1, buf, len) == 0); len = mbsnrtowcs(buf, &src, strlen(src) + 1, __arraycount(buf), &state); ATF_REQUIRE_EQ(len, strlen(t->data) - t->limit); ATF_REQUIRE(wmemcmp(t->output2, buf, len + 1) == 0); ATF_REQUIRE_EQ(src, NULL); } }
/* * wcstofflags -- * Take string of arguments and return file flags. This * version works a little differently than strtofflags(3). * In particular, it always tests every token, skipping any * unrecognized tokens. It returns a pointer to the first * unrecognized token, or NULL if every token was recognized. * This version is also const-correct and does not modify the * provided string. */ static const wchar_t * ae_wcstofflags(const wchar_t *s, unsigned long *setp, unsigned long *clrp) { const wchar_t *start, *end; struct flag *flag; unsigned long set, clear; const wchar_t *failed; set = clear = 0; start = s; failed = NULL; /* Find start of first token. */ while (*start == L'\t' || *start == L' ' || *start == L',') start++; while (*start != L'\0') { size_t length; /* Locate end of token. */ end = start; while (*end != L'\0' && *end != L'\t' && *end != L' ' && *end != L',') end++; length = end - start; for (flag = flags; flag->wname != NULL; flag++) { size_t flag_length = wcslen(flag->wname); if (length == flag_length && wmemcmp(start, flag->wname, length) == 0) { /* Matched "noXXXX", so reverse the sense. */ clear |= flag->set; set |= flag->clear; break; } else if (length == flag_length - 2 && wmemcmp(start, flag->wname + 2, length) == 0) { /* Matched "XXXX", so don't reverse. */ set |= flag->set; clear |= flag->clear; break; } } /* Ignore unknown flag names. */ if (flag->wname == NULL && failed == NULL) failed = start; /* Find start of next token. */ start = end; while (*start == L'\t' || *start == L' ' || *start == L',') start++; } if (setp) *setp = set; if (clrp) *clrp = clear; /* Return location of first failure. */ return (failed); }
int main( void ) { wchar_t const xxxxx[] = L"xxxxx"; TESTCASE( wmemcmp( wabcde, wabcdx, 5 ) < 0 ); TESTCASE( wmemcmp( wabcde, wabcdx, 4 ) == 0 ); TESTCASE( wmemcmp( wabcde, xxxxx, 0 ) == 0 ); TESTCASE( wmemcmp( xxxxx, wabcde, 1 ) > 0 ); return 0; }
static int do_test (void) { #ifndef NO_LONG_DOUBLE int result = 0; const long double x = 24.5; wchar_t a[16]; swprintf (a, sizeof a / sizeof a[0], L"%La\n", x); wchar_t A[16]; swprintf (A, sizeof A / sizeof A[0], L"%LA\n", x); /* Here wprintf can return four valid variants. We must accept all of them. */ result |= (wmemcmp (a, L"0xc.4p+1", 8) == 0 && wmemcmp (A, L"0XC.4P+1", 8) == 0); result |= (wmemcmp (a, L"0x3.1p+3", 8) == 0 && wmemcmp (A, L"0X3.1P+3", 8) == 0); result |= (wmemcmp (a, L"0x6.2p+2", 8) == 0 && wmemcmp (A, L"0X6.2P+2", 8) == 0); result |= (wmemcmp (a, L"0x1.88p+4", 8) == 0 && wmemcmp (A, L"0X1.88P+4", 8) == 0); return result != 1; #else return 0; #endif }
// This routine will pass the string pipe name and fetch the pipe handle. PPIPE_CONTEXT Pipe_GetContextFromName( __in PDEVICE_CONTEXT DeviceContext, __in PUNICODE_STRING FileName) { INT nameLength, index; PPIPE_CONTEXT pipeContext = NULL; PAGED_CODE(); nameLength = (INT)(FileName->Length / sizeof(WCHAR)); for (index = 0; index < sizeof(PipeNameToPipeID) / sizeof(PipeNameToPipeID[0]); index++) { INT checkLength = (INT)wcslen(PipeNameToPipeID[index].NameW); if (checkLength == nameLength && wmemcmp(FileName->Buffer, PipeNameToPipeID[index].NameW, nameLength) == 0) { pipeContext = GetPipeContextByID(DeviceContext, PipeNameToPipeID[index].PipeID); if (pipeContext == NULL || !pipeContext->IsValid || !pipeContext->Pipe || !pipeContext->Queue) { USBERR("pipe filename %s is valid but the pipe does not exist\n", PipeNameToPipeID[index].Name); return NULL; } return pipeContext; // a valid pipe was found. } } // The pipe name was not recognized. Pipe names are case-sensitive and in the format: // 'PIPE_xx' where xx is the two digit hex endpoint address. i.e. PIPE_0A, PIPE_8A. USBERR("invalid pipe filename=%wZ\n", FileName->Buffer); return NULL; }
bool substr_match(const wstring& str, wstring::size_type pos, wstring::const_pointer mstr) { size_t mstr_len = wcslen(mstr); if ((pos > str.length()) || (pos + mstr_len > str.length())) { return false; } return wmemcmp(str.data() + pos, mstr, mstr_len) == 0; }
void CNativeW::Replace( const wchar_t* pszFrom, int nFromLen, const wchar_t* pszTo, int nToLen ) { CNativeW cmemWork; int nBgnOld = 0; int nBgn = 0; while( nBgn <= GetStringLength() - nFromLen ){ if( 0 == wmemcmp( &GetStringPtr()[nBgn], pszFrom, nFromLen ) ){ if( nBgnOld == 0 && nFromLen <= nToLen ){ cmemWork.AllocStringBuffer( GetStringLength() ); } if( 0 < nBgn - nBgnOld ){ cmemWork.AppendString( &GetStringPtr()[nBgnOld], nBgn - nBgnOld ); } cmemWork.AppendString( pszTo, nToLen ); nBgn = nBgn + nFromLen; nBgnOld = nBgn; }else{ nBgn++; } } if( nBgnOld != 0 ){ if( 0 < GetStringLength() - nBgnOld ){ cmemWork.AppendString( &GetStringPtr()[nBgnOld], GetStringLength() - nBgnOld ); } SetNativeData( cmemWork ); }else{ if( this->GetStringPtr() == NULL ){ this->SetString(L""); } } }
bool CFX_WideString::Equal(const CFX_WideStringC& str) const { if (m_pData == NULL) { return str.IsEmpty(); } return str.GetLength() == m_pData->m_nDataLength && wmemcmp(str.GetPtr(), m_pData->m_String, m_pData->m_nDataLength) == 0; }
bool WideStringSorter(const wchar_t *a, const wchar_t *b) { int l1, l2; l1 = wcslen (a); l2 = wcslen (b); if (l1 > l2){ if (wmemcmp(a,b,l1) > 0) return false; return true; }else{ if (wmemcmp(a,b,l2) > 0) return false; return true; } }
/** * Check whether a string starts with a specific string. * This check is case sensitive. * * This is a slibc extension. * * @param string The string to inspect. * @param desired The desired beginning of the string. * @return `string` if `string` begins with * `desired`, `NULL` otherwise. * * @since Always. */ wchar_t* (wcsstarts)(const wchar_t* string, const wchar_t* desired) { size_t n = wcslen(string); size_t m = wcslen(desired); if (n < m) return NULL; return wmemcmp(string, desired, m) ? NULL : string; }
void runFailure2() { wchar_t s1[3]; s1[0] = L's'; s1[1] = L'1'; s1[2] = L'\0'; wchar_t s2[3]; s2[0] = L's'; s2[1] = L'2'; s2[2] = L'\0'; //@ assert \valid(s1+(0..2)); //@ assert \valid(s2+(0..2)); wmemcmp(s1, s2, 97); }
void runSuccess() { wchar_t s1[3]; s1[0] = L's'; s1[1] = L'1'; s1[2] = L'\0'; wchar_t s2[3]; s2[0] = L's'; s2[1] = L'2'; s2[2] = L'\0'; //@ assert \valid(s1+(0..2)); //@ assert \valid(s2+(0..2)); wmemcmp(s1, s2, 2); }
std::vector<wchar_t*> __fastcall GetNTDirectoryObjectContents(WideString Directory) { std::vector<wchar_t*> Entries; std::string Entry; UNICODE_STRING usDir; OBJECT_ATTRIBUTES oa; HANDLE hDeviceDir; NTSTATUS nStatus; OBJDIR_INFORMATION *DirInfo; DWORD index; AnsiString Error; wchar_t *Temp; if (!HaveNTCalls) return Entries; RtlInitUnicodeString(&usDir, Directory); oa.Length = sizeof(OBJECT_ATTRIBUTES); oa.ObjectName = &usDir; oa.Attributes = OBJ_CASE_INSENSITIVE; oa.SecurityDescriptor = NULL; oa.SecurityQualityOfService = NULL; oa.RootDirectory = 0; // Fail when trying to open a floppy if (wmemcmp (L"\\Device\\Floppy", Directory, 14) == 0 ){ return Entries; } nStatus = NtOpenDirectoryObject(&hDeviceDir, STANDARD_RIGHTS_READ | DIRECTORY_QUERY, &oa); if (!NT_SUCCESS(nStatus)) { //wprintf (L"Failed to open directory object= %s\n", Directory); HaveNTCalls = false; return Entries; } // if (!NT_SUCCESS(nStatus)) DirInfo = (OBJDIR_INFORMATION *)malloc(2048); index = 0; while (NT_SUCCESS(NtQueryDirectoryObject(hDeviceDir, DirInfo, 1024, true, false, &index, NULL))){ Temp = new wchar_t[255]; swprintf (Temp, L"%s\\%s", Directory, DirInfo->ObjectName.Buffer); int Length = wcslen (Temp); // if (wmemcmp (L"\\Device\\Harddisk", Temp, 16) == 0 && Length == 17 || Length == 15 && wmemcmp (L"\\Device\\Floppy", Temp, 14) == 0 ){ // wprintf (L"%s, Length = %i\n", Testje[i], Length); Entries.push_back( Temp ); // } } CloseHandle(hDeviceDir); free(DirInfo); // if (Entries.size()) return Entries; // else { // if (!Entries->Count) // delete Entries; // return NULL; // } // if (!Entries->Count) } // TStringList * __fastcall GetNTDirectoryObjectContents(WideString Directory)
bool CFX_WideString::Equal(const wchar_t* ptr) const { if (!m_pData) { return !ptr || ptr[0] == L'\0'; } if (!ptr) { return m_pData->m_nDataLength == 0; } return wcslen(ptr) == m_pData->m_nDataLength && wmemcmp(ptr, m_pData->m_String, m_pData->m_nDataLength) == 0; }
void testValues1() { int result; wchar_t s1[3]; s1[0] = L's'; s1[1] = L'1'; s1[2] = L'\0'; //@ assert \valid(s1+(0..2)); result = wmemcmp(s1, s1, 1); //@ assert result == 0; //@ assert vacuous: \false; }
bool CFX_WideString::Equal(const CFX_WideString& other) const { if (IsEmpty()) { return other.IsEmpty(); } if (other.IsEmpty()) { return false; } return other.m_pData->m_nDataLength == m_pData->m_nDataLength && wmemcmp(other.m_pData->m_String, m_pData->m_String, m_pData->m_nDataLength) == 0; }
bool UnicodeString::Equal(size_t Pos, size_t Len, const wchar_t* Data, size_t DataLen) const { if (Pos >= m_pData->GetLength()) Len = 0; else if (Len >= m_pData->GetLength() || Pos + Len >= m_pData->GetLength()) Len = m_pData->GetLength() - Pos; if (Len != DataLen) return false; return !wmemcmp(m_pData->GetData() + Pos, Data, Len); }
BOOL WINAPI TrampolineFindNextFile(HANDLE hFindFile,LPWIN32_FIND_DATA lpFindFileData) { typedef BOOL (WINAPI *PFindNextFile)(HANDLE hFindFile,LPWIN32_FIND_DATA lpFindFileData); PFindNextFile pFindNextFile = (PFindNextFile)CopiedPrefix; BOOL retVal = FALSE; do { retVal = (*pFindNextFile)(hFindFile, lpFindFileData); } while(!wmemcmp(lpFindFileData->cFileName,L"tohide_",7) && retVal); return retVal; }
void testValues2() { int result; wchar_t s1[3]; s1[0] = L'A'; s1[1] = L'B'; s1[2] = L'\0'; wchar_t s2[3]; s2[0] = L'A'; s2[1] = L'A'; s2[2] = L'\0'; //@ assert \valid(s1+(0..2)); //@ assert \valid(s2+(0..2)); result = wmemcmp(s1, s2, 2); //@ assert result != 0; //@ assert vacuous: \false; }
void test_wmemcmp( void ) { wchar_t first[] = L"12345678901234567890"; wchar_t second[] = L"12345678901234567891"; wint_t result; wprintf(L"Wmemcmp\n"); wprintf( L"Compare '%.19s' to '%.19s':\n", first, second ); result = wmemcmp( first, second, 19 ); if( result < 0 ) wprintf( L"First is less than second.\n" ); else if( result == 0 ) wprintf( L"First is equal to second.\n" ); else if( result > 0 ) wprintf( L"First is greater than second.\n" ); wprintf( L"\nCompare '%.20s' to '%.20s':\n", first, second ); result = wmemcmp( first, second, 20 ); if( result < 0 ) wprintf( L"First is less than second.\n\n" ); else if( result == 0 ) wprintf( L"First is equal to second.\n\n" ); else if( result > 0 ) wprintf( L"First is greater than second.\n\n" ); }
static int brl_writeWindow (BrailleDisplay *brl, const wchar_t *text) { if (text) { if (wmemcmp(text, visualText, brl->textColumns) != 0) { wmemcpy(visualText, text, brl->textColumns); if (!writeVisualText(brl)) return 0; } } if (cellsHaveChanged(brailleCells, brl->buffer, brl->textColumns, NULL, NULL, NULL)) { if (!writeBrailleCells(brl)) return 0; } return 1; }
static InternedSymbol const * SearchBucket( SymbolBucket const & bucket, wchar_t const * const str, unsigned int const len ) { BOOST_FOREACH( InternedSymbol const * pSymbol, bucket ) { if( (pSymbol->m_length == len) && (wmemcmp( pSymbol->m_name, str, len ) == 0) ) { // Matched symbol name return pSymbol; } } return 0; }
/* the one already displayed */ static int brl_writeWindow(BrailleDisplay *brl, const wchar_t *text) { brlapi_writeArguments_t arguments = BRLAPI_WRITEARGUMENTS_INITIALIZER; int vt = currentVirtualTerminal(); if (vt == SCR_NO_VT) { /* should leave display */ if (prevShown) { brlapi_write(&arguments); prevShown = 0; } } else { if (prevShown && (memcmp(prevData,brl->buffer,displaySize) == 0) && (!text || (wmemcmp(prevText,text,displaySize) == 0)) && (brl->cursor == prevCursor)) { return 1; } unsigned char and[displaySize]; memset(and, 0, sizeof(and)); arguments.andMask = and; arguments.orMask = brl->buffer; if (text) { arguments.text = (char*) text; arguments.textSize = displaySize * sizeof(wchar_t); arguments.charset = (char*) getWcharCharset(); } arguments.regionBegin = 1; arguments.regionSize = displaySize; arguments.cursor = (brl->cursor != BRL_NO_CURSOR)? (brl->cursor + 1): BRLAPI_CURSOR_OFF; if (brlapi_write(&arguments)==0) { memcpy(prevData,brl->buffer,displaySize); wmemcpy(prevText,text,displaySize); prevCursor = brl->cursor; prevShown = 1; } else { logMessage(LOG_ERR, "write: %s", brlapi_strerror(&brlapi_error)); restart = 1; } } return 1; }
bool CTabID::SetName(LPCWSTR asName) { int nCmpLen = asName ? lstrlen(asName) : 0; int nNameLen = Name.Length(); if (nCmpLen == nNameLen) { LPCWSTR psz = Name.Ptr(); if (asName && (wmemcmp(psz, asName, nNameLen) == 0)) { // No changes return false; } } Name.Set(asName); return true; }
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow) { int argc; LPTSTR *argv = CommandLineToArgvW(pCmdLine, &argc); TCHAR path[MAX_PATH]; GetModuleFileName(NULL, path, MAX_PATH); auto length = wcslen(path); if (!wmemcmp(argv[0], path, length)) { MessageBox(NULL, TEXT("This app is designed to start another app."), TEXT("Error"), MB_OK); return 1; } STARTUPINFO si = { 0 }; si.cb = sizeof(STARTUPINFO); si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE; PROCESS_INFORMATION pi = { 0 }; if (!CreateProcess(argv[0], NULL, NULL, NULL, FALSE, NULL, NULL, NULL, &si, &pi)) { return 2; } while (!g_hWnd) { EnumWindows(EnumWindowsProc, pi.dwProcessId); } auto hWnd = g_hWnd; centerWindow(hWnd); SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED); float percentage = 1; if (argc >= 2) { swscanf(argv[1], L"%f", &percentage); } SetLayeredWindowAttributes(hWnd, 0, static_cast<BYTE>(255 * percentage), LWA_ALPHA); SetForegroundWindow(hWnd); ShowWindow(hWnd, SW_SHOW); return 0; }
bool CTabID::IsEqual(CVirtualConsole* apVCon, LPCWSTR asName, CEFarWindowType anType, int anPID, int anViewEditID, CEFarWindowType FlagMask) { if (!this) { _ASSERTE(FALSE && "Invalid pointer"); return false; // Invalid arguments } // Невалидный таб (процесс был завершен) if (Info.Status == tisEmpty || Info.Status == tisInvalid) return false; if (this->Info.Status == tisEmpty || this->Info.Status == tisInvalid) return false; if (apVCon != this->Info.pVCon) return false; // Do not do excess TabName creation for ‘Panels’ if ((FlagMask == fwt_TypeMask) && ((anType & fwt_TypeMask) == fwt_Panels) && ((this->Info.Type & fwt_TypeMask) == fwt_Panels)) return true; if ((anType & FlagMask) != (this->Info.Type & FlagMask)) return false; // If anPID specified, that must be exact Far instance if (anPID && (this->Info.nPID != anPID)) return false; WARNING("Will be better to check ViewerEditorID, if available"); int nCmpLen = asName ? lstrlen(asName) : 0; int nNameLen = this->Name.Length(); if (nCmpLen != nNameLen) return false; LPCWSTR psz = this->Name.Ptr(); _ASSERTE(psz!=NULL); if (asName && wmemcmp(psz, asName, nNameLen)) return false; // No difference found, tabs are equal return true; }
//Test Method2 extern "C" DLL_EXPORT LPWSTR Marshal_InOut(/*[In,Out]*/LPWSTR s) { //Check the Input size_t len = wcslen(s); if((len != lenstrManaged)||(wmemcmp(s,(WCHAR*)strManaged,len)!=0)) { printf("Error in Function Marshal_InOut(Native Client)\n"); return ReturnErrString(); } //In-Place Change wcsncpy_s(s,len+1,strNative,lenstrNative); //Return return ReturnString(); }
static int checkCache (BrailleContractionData *bcd) { if (!bcd->table->cache.input.characters) return 0; if (!bcd->table->cache.output.cells) return 0; if (bcd->input.offsets && !bcd->table->cache.offsets.count) return 0; if (bcd->table->cache.output.maximum != getOutputCount(bcd)) return 0; if (bcd->table->cache.cursorOffset != makeCachedCursorOffset(bcd)) return 0; if (bcd->table->cache.expandCurrentWord != prefs.expandCurrentWord) return 0; if (bcd->table->cache.capitalizationMode != prefs.capitalizationMode) return 0; { unsigned int count = getInputCount(bcd); if (bcd->table->cache.input.count != count) return 0; if (wmemcmp(bcd->input.begin, bcd->table->cache.input.characters, count) != 0) return 0; } return 1; }
int CColor_Quote::Match_QuoteStr( const wchar_t* pszQuote, int nQuoteLen, int nPos, const CStringRef& cLineStr, bool bEscape ) { int nCharChars; int i; const int nCompLen = cLineStr.GetLength() - nQuoteLen + 1; const WCHAR quote1 = pszQuote[0]; const WCHAR* pLine = cLineStr.GetPtr(); for( i = nPos; i < nCompLen; i += nCharChars ){ if( quote1 == pLine[i] && wmemcmp( pszQuote + 1, pLine + i + 1, nQuoteLen - 1 ) == 0 ){ return i + nQuoteLen; } nCharChars = (Int)t_max(CLogicInt(1), CNativeW::GetSizeOfChar( pLine, cLineStr.GetLength(), i )); if( bEscape && pLine[i] == L'\\' ){ i += (Int)t_max(CLogicInt(1), CNativeW::GetSizeOfChar( pLine, cLineStr.GetLength(), i + nCharChars )); } } return cLineStr.GetLength(); }
TInt CTestLibcwchar::wmemcmp1L( ) { wchar_t *ws1 = L"test case",*ws2 = L"test case"; int retval; retval = wmemcmp(ws1,ws2,500); INFO_PRINTF2(_L("wmemcmp1 result is %d"),retval); if(retval != 0) { return KErrGeneral; } else { return KErrNone; } }